Skip to content

Commit

Permalink
Add change_column_comment and change_table_comment for `change_ta…
Browse files Browse the repository at this point in the history
…ble` definition
  • Loading branch information
mechnicov committed Apr 27, 2024
1 parent 0a9e39d commit 81b37be
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions activerecord/CHANGELOG.md
Expand Up @@ -731,6 +731,17 @@

*Tristan Fellows*

* Add `change_column_comment` and `change_table_comment` for `change_table` definition.

```ruby
change_table :users do |t|
t.change_column_comment :login, "Username"
t.change_table_comment "Usual users"
end
```

*Edem Topuzov*

* Allow for more complex hash arguments for `order` which mimics `where` in `ActiveRecord::Relation`.

```ruby
Expand Down
Expand Up @@ -701,6 +701,8 @@ def add_column(name, type, **options)
# t.remove_index
# t.remove_check_constraint
# t.remove_timestamps
# t.change_column_comment
# t.change_table_comment
# end
#
class Table
Expand Down Expand Up @@ -941,6 +943,24 @@ def check_constraint_exists?(*args, **options)
@base.check_constraint_exists?(name, *args, **options)
end

# Changes the comment for a column.
#
# t.change_column_comment(:state, "State column comment")
#
# See {connection.change_column_comment}[rdoc-ref:SchemaStatements#change_column_comment]
def change_column_comment(column_name, comment_or_changes)
@base.change_column_comment(name, column_name, comment_or_changes)
end

# Changes the comment for a table.
#
# t.change_table_comment("Table comment")
#
# See {connection.change_table_comment}[rdoc-ref:SchemaStatements#change_table_comment]
def change_table_comment(comment_or_changes)
@base.change_table_comment(name, comment_or_changes)
end

private
def raise_on_if_exist_options(options)
unrecognized_option = options.keys.find do |key|
Expand Down
14 changes: 14 additions & 0 deletions activerecord/test/cases/migration/change_table_test.rb
Expand Up @@ -339,6 +339,20 @@ def test_remove_check_constraint_removes_check_constraint
end
end

def test_change_column_comment
with_change_table do |t|
expect :change_column_comment, nil, [:delete_me, :bar, "Edited column comment"]
t.change_column_comment :bar, "Edited column comment"
end
end

def test_change_table_comment
with_change_table do |t|
expect :change_table_comment, nil, [:delete_me, "Edited table comment"]
t.change_table_comment "Edited table comment"
end
end

def test_remove_column_with_if_exists_raises_error
assert_raises(ArgumentError) do
with_change_table do |t|
Expand Down

0 comments on commit 81b37be

Please sign in to comment.