mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #33618 from yskkin/bulk_change_table_comment
Fix bulk change table ignores comment option on PostgreSQL.
This commit is contained in:
commit
f7a4b875df
2 changed files with 16 additions and 3 deletions
|
@ -700,6 +700,11 @@ module ActiveRecord
|
|||
sql
|
||||
end
|
||||
|
||||
def add_column_for_alter(table_name, column_name, type, options = {})
|
||||
return super unless options.key?(:comment)
|
||||
[super, Proc.new { change_column_comment(table_name, column_name, options[:comment]) }]
|
||||
end
|
||||
|
||||
def change_column_for_alter(table_name, column_name, type, options = {})
|
||||
sqls = [change_column_sql(table_name, column_name, type, options)]
|
||||
sqls << change_column_default_for_alter(table_name, column_name, options[:default]) if options.key?(:default)
|
||||
|
@ -708,7 +713,6 @@ module ActiveRecord
|
|||
sqls
|
||||
end
|
||||
|
||||
|
||||
# Changes the default value of a table column.
|
||||
def change_column_default_for_alter(table_name, column_name, default_or_changes) # :nodoc:
|
||||
column = column_for(table_name, column_name)
|
||||
|
|
|
@ -793,12 +793,20 @@ if ActiveRecord::Base.connection.supports_bulk_alter?
|
|||
end
|
||||
|
||||
def test_adding_multiple_columns
|
||||
assert_queries(1) do
|
||||
classname = ActiveRecord::Base.connection.class.name[/[^:]*$/]
|
||||
expected_query_count = {
|
||||
"Mysql2Adapter" => 1,
|
||||
"PostgreSQLAdapter" => 2, # one for bulk change, one for comment
|
||||
}.fetch(classname) {
|
||||
raise "need an expected query count for #{classname}"
|
||||
}
|
||||
|
||||
assert_queries(expected_query_count) do
|
||||
with_bulk_change_table do |t|
|
||||
t.column :name, :string
|
||||
t.string :qualification, :experience
|
||||
t.integer :age, default: 0
|
||||
t.date :birthdate
|
||||
t.date :birthdate, comment: "This is a comment"
|
||||
t.timestamps null: true
|
||||
end
|
||||
end
|
||||
|
@ -806,6 +814,7 @@ if ActiveRecord::Base.connection.supports_bulk_alter?
|
|||
assert_equal 8, columns.size
|
||||
[:name, :qualification, :experience].each { |s| assert_equal :string, column(s).type }
|
||||
assert_equal "0", column(:age).default
|
||||
assert_equal "This is a comment", column(:birthdate).comment
|
||||
end
|
||||
|
||||
def test_removing_columns
|
||||
|
|
Loading…
Reference in a new issue