aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/schema_dumper.rb
diff options
context:
space:
mode:
authorAndrey Novikov <envek@envek.name>2016-01-03 21:13:53 +0300
committerAndrey Novikov <envek@envek.name>2016-04-16 10:17:26 +0300
commitc690b9ce39c893077b48fa5b27af87e995f97e9b (patch)
tree925a00ba04b8a144041b6c823bd8bceacd6084f1 /activerecord/lib/active_record/schema_dumper.rb
parent39e087cbf5628ecc351fc86a3a1e320be193bf29 (diff)
downloadrails-c690b9ce39c893077b48fa5b27af87e995f97e9b.tar.gz
rails-c690b9ce39c893077b48fa5b27af87e995f97e9b.tar.bz2
rails-c690b9ce39c893077b48fa5b27af87e995f97e9b.zip
Add support for specifying comments for tables, columns, and indexes.
Comments are specified in migrations, stored in database itself (in its schema), and dumped into db/schema.rb file. This allows to generate good documentation and explain columns and tables' purpose to everyone from new developers to database administrators. For PostgreSQL and MySQL only. SQLite does not support comments at the moment. See docs for PostgreSQL: http://www.postgresql.org/docs/current/static/sql-comment.html See docs for MySQL: http://dev.mysql.com/doc/refman/5.7/en/create-table.html
Diffstat (limited to 'activerecord/lib/active_record/schema_dumper.rb')
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index affcd9aed1..bc4adb4ed7 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -138,6 +138,9 @@ HEADER
table_options = @connection.table_options(table)
tbl.print ", options: #{table_options.inspect}" unless table_options.blank?
+ comment = @connection.table_comment(table)
+ tbl.print ", comment: #{comment.inspect}" if comment
+
tbl.puts " do |t|"
# then dump all non-primary key columns
@@ -209,6 +212,7 @@ HEADER
statement_parts << "where: #{index.where.inspect}" if index.where
statement_parts << "using: #{index.using.inspect}" if index.using
statement_parts << "type: #{index.type.inspect}" if index.type
+ statement_parts << "comment: #{index.comment.inspect}" if index.comment
" #{statement_parts.join(', ')}"
end