From c690b9ce39c893077b48fa5b27af87e995f97e9b Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Sun, 3 Jan 2016 21:13:53 +0300 Subject: 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 --- activerecord/lib/active_record/schema_dumper.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/lib/active_record/schema_dumper.rb') 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 -- cgit v1.2.3