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

Fix bulk change table ignores comment option on PostgreSQL. #33618

Merged
merged 1 commit into from
Aug 15, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@ def change_column_sql(table_name, column_name, type, options = {})
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)
Expand All @@ -708,7 +713,6 @@ def change_column_for_alter(table_name, column_name, type, options = {})
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)
Expand Down
13 changes: 11 additions & 2 deletions activerecord/test/cases/migration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -793,19 +793,28 @@ def setup
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

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
Expand Down