aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-23 05:55:48 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-23 05:55:48 +0900
commitb798c5b796f58a9286e1a037db4453750cd26f95 (patch)
tree928e9fa437218783bd46c91e3ebb1e925e329ca8 /activerecord
parent18346bd52ab84fca996f4dfc1dd110ab2edf1f46 (diff)
downloadrails-b798c5b796f58a9286e1a037db4453750cd26f95.tar.gz
rails-b798c5b796f58a9286e1a037db4453750cd26f95.tar.bz2
rails-b798c5b796f58a9286e1a037db4453750cd26f95.zip
Prevent extra `column_for` for `change_column_{default,null,comment}`
`change_column_{default,null,comment}` in mysql2 adapter are passing `column.sql_type` as `type` to `change_column` to intend keeping previous type. But `column_for` requires extra query, so use passing `nil` to `type` explicitly in the internal for the purpose.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb11
1 files changed, 4 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 46ab8f3edd..ae991d3d79 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -356,23 +356,19 @@ module ActiveRecord
def change_column_default(table_name, column_name, default_or_changes) #:nodoc:
default = extract_new_default_value(default_or_changes)
- column = column_for(table_name, column_name)
- change_column table_name, column_name, column.sql_type, default: default
+ change_column table_name, column_name, nil, default: default
end
def change_column_null(table_name, column_name, null, default = nil) #:nodoc:
- column = column_for(table_name, column_name)
-
unless null || default.nil?
execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
end
- change_column table_name, column_name, column.sql_type, null: null
+ change_column table_name, column_name, nil, null: null
end
def change_column_comment(table_name, column_name, comment) #:nodoc:
- column = column_for(table_name, column_name)
- change_column table_name, column_name, column.sql_type, comment: comment
+ change_column table_name, column_name, nil, comment: comment
end
def change_column(table_name, column_name, type, options = {}) #:nodoc:
@@ -678,6 +674,7 @@ module ActiveRecord
def change_column_sql(table_name, column_name, type, options = {})
column = column_for(table_name, column_name)
+ type ||= column.sql_type
unless options.key?(:default)
options[:default] = column.default