未验证 提交 ee1fda12 编写于 作者: M Matthew Draper 提交者: GitHub

Merge pull request #31773 from dinahshi/postgresql_bulk_patch

Postgresql bulk_change_table should flatten procs array
...@@ -375,7 +375,7 @@ def bulk_change_table(table_name, operations) ...@@ -375,7 +375,7 @@ def bulk_change_table(table_name, operations)
if respond_to?(method, true) if respond_to?(method, true)
sqls, procs = Array(send(method, table, *arguments)).partition { |v| v.is_a?(String) } sqls, procs = Array(send(method, table, *arguments)).partition { |v| v.is_a?(String) }
sql_fragments << sqls sql_fragments << sqls
non_combinable_operations << procs if procs.present? non_combinable_operations.concat(procs)
else else
execute "ALTER TABLE #{quote_table_name(table_name)} #{sql_fragments.join(", ")}" unless sql_fragments.empty? execute "ALTER TABLE #{quote_table_name(table_name)} #{sql_fragments.join(", ")}" unless sql_fragments.empty?
non_combinable_operations.each(&:call) non_combinable_operations.each(&:call)
......
...@@ -881,7 +881,7 @@ def test_changing_columns ...@@ -881,7 +881,7 @@ def test_changing_columns
classname = ActiveRecord::Base.connection.class.name[/[^:]*$/] classname = ActiveRecord::Base.connection.class.name[/[^:]*$/]
expected_query_count = { expected_query_count = {
"Mysql2Adapter" => 3, # one query for columns, one query for primary key, one query to do the bulk change "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) { }.fetch(classname) {
raise "need an expected query count for #{classname}" raise "need an expected query count for #{classname}"
} }
...@@ -889,12 +889,13 @@ def test_changing_columns ...@@ -889,12 +889,13 @@ def test_changing_columns
assert_queries(expected_query_count, ignore_none: true) do assert_queries(expected_query_count, ignore_none: true) do
with_bulk_change_table do |t| with_bulk_change_table do |t|
t.change :name, :string, default: "NONAME" t.change :name, :string, default: "NONAME"
t.change :birthdate, :datetime t.change :birthdate, :datetime, comment: "This is a comment"
end end
end end
assert_equal "NONAME", column(:name).default assert_equal "NONAME", column(:name).default
assert_equal :datetime, column(:birthdate).type assert_equal :datetime, column(:birthdate).type
assert_equal "This is a comment", column(:birthdate).comment
end end
private private
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册