Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement change_table_comment and change_column_comment #30677

Merged
merged 1 commit into from Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions activerecord/test/cases/comment_test.rb
Expand Up @@ -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