Permalink
Browse files

MySQL, PostgreSQL: change_column_default quotes the default value and…

… doesn't lose column type information. References #3987, closes #6664.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5935 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent e310344 commit a491f928608f763cf4fa6067f7cf9529197afcae @jeremy jeremy committed Jan 15, 2007
View
@@ -1,5 +1,7 @@
*SVN*
+* MySQL, PostgreSQL: change_column_default quotes the default value and doesn't lose column type information. #3987, #6664 [Jonathan Viney, manfred, altano@bigfoot.com]
+
* Oracle: create_table takes a :sequence_name option to override the 'tablename_seq' default. #7000 [Michael Schoen]
* MySQL: retain SSL settings on reconnect. #6976 [randyv2]
@@ -360,7 +360,7 @@ def rename_table(name, new_name)
def change_column_default(table_name, column_name, default) #:nodoc:
current_type = select_one("SHOW COLUMNS FROM #{table_name} LIKE '#{column_name}'")["Type"]
- change_column(table_name, column_name, current_type, { :default => default })
+ execute("ALTER TABLE #{table_name} CHANGE #{column_name} #{column_name} #{current_type} DEFAULT #{quote(default)}")
end
def change_column(table_name, column_name, type, options = {}) #:nodoc:
@@ -349,7 +349,7 @@ def change_column(table_name, column_name, type, options = {}) #:nodoc:
end
def change_column_default(table_name, column_name, default) #:nodoc:
- execute "ALTER TABLE #{table_name} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT '#{default}'"
+ execute "ALTER TABLE #{table_name} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{quote(default)}"
end
def rename_column(table_name, column_name, new_column_name) #:nodoc:
@@ -425,14 +425,26 @@ def test_change_column
end
def test_change_column_with_new_default
- Person.connection.add_column "people", "administrator", :boolean, :default => 1
+ Person.connection.add_column "people", "administrator", :boolean, :default => true
Person.reset_column_information
assert Person.new.administrator?
- assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => 0 }
+ assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => false }
Person.reset_column_information
assert !Person.new.administrator?
end
+
+ def test_change_column_default
+ Person.connection.change_column_default "people", "first_name", "Tester"
+ Person.reset_column_information
+ assert_equal "Tester", Person.new.first_name
+ end
+
+ def test_change_column_default_to_null
+ Person.connection.change_column_default "people", "first_name", nil
+ Person.reset_column_information
+ assert_nil Person.new.first_name
+ end
def test_add_table
assert !Reminder.table_exists?

0 comments on commit a491f92

Please sign in to comment.