aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAlecs Popa <alecs.popa@gmail.com>2017-09-21 19:55:16 +0300
committerAlecs Popa <alecs.popa@gmail.com>2017-09-22 10:32:26 +0300
commit72a22fa9299d41b6d088bb4a0c3c6807f5bed07d (patch)
tree8ebead308a37245e01308b68e0509687ef2b766b /activerecord
parent30ae39efc22c3eae10260c0a3bde5cd0d2553f2f (diff)
downloadrails-72a22fa9299d41b6d088bb4a0c3c6807f5bed07d.tar.gz
rails-72a22fa9299d41b6d088bb4a0c3c6807f5bed07d.tar.bz2
rails-72a22fa9299d41b6d088bb4a0c3c6807f5bed07d.zip
Implement change_table_comment and change_column_comment for MySql Adapter
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb10
-rw-r--r--activerecord/test/cases/comment_test.rb22
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