mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
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
This commit is contained in:
@@ -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 @@ module ActiveRecord
|
||||
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 @@ module ActiveRecord
|
||||
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 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||
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?
|
||||
|
||||
Reference in New Issue
Block a user