Skip to content

Commit 71a36f4

Browse files
committed
[Rails5] Fix #change_column_default.
1 parent 611e81a commit 71a36f4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ def change_column(table_name, column_name, type, options = {})
124124
sql_commands.each { |c| do_execute(c) }
125125
end
126126

127-
def change_column_default(table_name, column_name, default)
127+
def change_column_default(table_name, column_name, default_or_changes)
128128
clear_cache!
129+
column = column_for(table_name, column_name)
130+
return unless column
129131
remove_default_constraint(table_name, column_name)
130-
column_object = schema_cache.columns(table_name).find { |c| c.name.to_s == column_name.to_s }
131-
do_execute "ALTER TABLE #{quote_table_name(table_name)} ADD CONSTRAINT #{default_constraint_name(table_name, column_name)} DEFAULT #{quote_default_expression(default, column_object)} FOR #{quote_column_name(column_name)}"
132+
default = extract_new_default_value(default_or_changes)
133+
do_execute "ALTER TABLE #{quote_table_name(table_name)} ADD CONSTRAINT #{default_constraint_name(table_name, column_name)} DEFAULT #{quote_default_expression(default, column)} FOR #{quote_column_name(column_name)}"
132134
clear_cache!
133135
end
134136

0 commit comments

Comments
 (0)