From 6019c268562d3d1e62c3ad649e81a1803f3e0732 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 15 Jan 2007 02:22:53 +0000 Subject: change_column accepts :default => nil. Closes #6956. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5937 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index db946478f9..eb9d0e94df 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -321,10 +321,10 @@ module ActiveRecord execute("ALTER TABLE #{table_name} ADD COLUMN #{column_name} #{type_to_sql(type, options[:limit])}") # Set optional default. If not null, update nulls to the new default. - unless default.nil? + if options_include_default?(options) change_column_default(table_name, column_name, default) if notnull - execute("UPDATE #{table_name} SET #{column_name}='#{default}' WHERE #{column_name} IS NULL") + execute("UPDATE #{table_name} SET #{column_name}=#{quote(default, options[:column])} WHERE #{column_name} IS NULL") end end @@ -345,7 +345,10 @@ module ActiveRecord rename_column(table_name, "#{column_name}_ar_tmp", column_name) commit_db_transaction end - change_column_default(table_name, column_name, options[:default]) unless options[:default].nil? + + if options_include_default?(options) + change_column_default(table_name, column_name, options[:default]) + end end def change_column_default(table_name, column_name, default) #:nodoc: -- cgit v1.2.3