提交 72a22fa9 编写于 作者: A Alecs Popa

Implement change_table_comment and change_column_comment for MySql Adapter

上级 30ae39ef
......@@ -311,6 +311,11 @@ def bulk_change_table(table_name, operations) #:nodoc:
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 @@ def change_column_null(table_name, column_name, null, default = nil) #:nodoc:
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
......
......@@ -142,5 +142,27 @@ def test_schema_dump_omits_blank_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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册