Merge pull request #31773 from dinahshi/postgresql_bulk_patch
Postgresql bulk_change_table should flatten procs array
This commit is contained in:
commit
ee1fda121e
@ -375,7 +375,7 @@ def bulk_change_table(table_name, operations)
|
||||
if respond_to?(method, true)
|
||||
sqls, procs = Array(send(method, table, *arguments)).partition { |v| v.is_a?(String) }
|
||||
sql_fragments << sqls
|
||||
non_combinable_operations << procs if procs.present?
|
||||
non_combinable_operations.concat(procs)
|
||||
else
|
||||
execute "ALTER TABLE #{quote_table_name(table_name)} #{sql_fragments.join(", ")}" unless sql_fragments.empty?
|
||||
non_combinable_operations.each(&:call)
|
||||
|
@ -881,7 +881,7 @@ def test_changing_columns
|
||||
classname = ActiveRecord::Base.connection.class.name[/[^:]*$/]
|
||||
expected_query_count = {
|
||||
"Mysql2Adapter" => 3, # one query for columns, one query for primary key, one query to do the bulk change
|
||||
"PostgreSQLAdapter" => 2, # one query for columns, one for bulk change
|
||||
"PostgreSQLAdapter" => 3, # one query for columns, one for bulk change, one for comment
|
||||
}.fetch(classname) {
|
||||
raise "need an expected query count for #{classname}"
|
||||
}
|
||||
@ -889,12 +889,13 @@ def test_changing_columns
|
||||
assert_queries(expected_query_count, ignore_none: true) do
|
||||
with_bulk_change_table do |t|
|
||||
t.change :name, :string, default: "NONAME"
|
||||
t.change :birthdate, :datetime
|
||||
t.change :birthdate, :datetime, comment: "This is a comment"
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal "NONAME", column(:name).default
|
||||
assert_equal :datetime, column(:birthdate).type
|
||||
assert_equal "This is a comment", column(:birthdate).comment
|
||||
end
|
||||
|
||||
private
|
||||
|
Loading…
Reference in New Issue
Block a user