diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-22 17:44:08 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-22 17:44:08 +0900 |
commit | a0277a974ce881d975b13634bcc7da17bc906844 (patch) | |
tree | fe9826618689fdc851b1f4d06eba234571e6ea1e /activerecord | |
parent | 7f3aab91b894f1125e838b92434001dbb13007c8 (diff) | |
parent | 72a22fa9299d41b6d088bb4a0c3c6807f5bed07d (diff) | |
download | rails-a0277a974ce881d975b13634bcc7da17bc906844.tar.gz rails-a0277a974ce881d975b13634bcc7da17bc906844.tar.bz2 rails-a0277a974ce881d975b13634bcc7da17bc906844.zip |
Merge pull request #30677 from alecspopa/master
Implement change_table_comment and change_column_comment
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/comment_test.rb | 22 |
2 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 7cd086084a..3dad43ced8 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -311,6 +311,11 @@ module ActiveRecord execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls}") end + def change_table_comment(table_name, comment) #:nodoc: + comment = "" if comment.nil? + execute("ALTER TABLE #{quote_table_name(table_name)} COMMENT #{quote(comment)}") + end + # Renames a table. # # Example: @@ -365,6 +370,11 @@ module ActiveRecord change_column table_name, column_name, column.sql_type, null: null end + def change_column_comment(table_name, column_name, comment) #:nodoc: + column = column_for(table_name, column_name) + change_column table_name, column_name, column.sql_type, comment: comment + end + def change_column(table_name, column_name, type, options = {}) #:nodoc: execute("ALTER TABLE #{quote_table_name(table_name)} #{change_column_sql(table_name, column_name, type, options)}") end diff --git a/activerecord/test/cases/comment_test.rb b/activerecord/test/cases/comment_test.rb index 1bcafd4b55..40eb3e08c1 100644 --- a/activerecord/test/cases/comment_test.rb +++ b/activerecord/test/cases/comment_test.rb @@ -142,5 +142,27 @@ if ActiveRecord::Base.connection.supports_comments? assert_match %r[t\.string\s+"absent_comment"\n], output assert_no_match %r[t\.string\s+"absent_comment", comment:\n], output end + + def test_change_table_comment + @connection.change_table_comment :commenteds, "Edited table comment" + assert_equal "Edited table comment", @connection.table_comment("commenteds") + end + + def test_change_table_comment_to_nil + @connection.change_table_comment :commenteds, nil + assert @connection.table_comment("commenteds").blank? + end + + def test_change_column_comment + @connection.change_column_comment :commenteds, :name, "Edited column comment" + column = Commented.columns_hash["name"] + assert_equal "Edited column comment", column.comment + end + + def test_change_column_comment_to_nil + @connection.change_column_comment :commenteds, :name, nil + column = Commented.columns_hash["name"] + assert_nil column.comment + end end end |