Created
March 2, 2013 10:49
-
-
Save denyago/5070488 to your computer and use it in GitHub Desktop.
List all models and their DB columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load models | |
Dir.foreach("app/models") { |f| require f if f =~ /rb$/ } | |
ActiveRecord::Base.descendants.each do |klass| | |
next if klass == "Rack::OAuth2::Server::Issuer".safe_constantize or klass == "Rack::OAuth2::Server::ActiveRecord".safe_constantize | |
begin | |
klass.columns.each_with_index {|c, i| printf "%-20s | %-19s | %-29s | %-10s\n", (i==0 ? klass.name : ''), c.name, c.sql_type, (c.null ? '' : 'not null') } | |
rescue => e | |
puts "*"*10 | |
puts "Error getting columns for #{klass}: #{e}" | |
puts "*"*10 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment