Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't carry default value when changing column for a binary type on M…
…ySQL [#3234 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Elomar França authored and josevalim committed May 16, 2010
1 parent 0706bdc commit ddadcc7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -506,7 +506,7 @@ def change_column_null(table_name, column_name, null, default = nil)
def change_column(table_name, column_name, type, options = {}) #:nodoc:
column = column_for(table_name, column_name)

unless options_include_default?(options)
if has_default?(type) && !options_include_default?(options)
options[:default] = column.default
end

Expand Down Expand Up @@ -655,6 +655,10 @@ def column_for(table_name, column_name)
end
column
end

def has_default?(sql_type)
sql_type =~ :binary || sql_type == :text #mysql forbids defaults on blob and text columns
end
end
end
end
10 changes: 10 additions & 0 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -823,6 +823,16 @@ def test_change_column_default
assert_equal "Tester", Person.new.first_name
end

def test_change_column_type_default_should_change
old_columns = Person.connection.columns(Person.table_name, "#{name} Columns")
assert !old_columns.find { |c| c.name == 'data' }

assert_nothing_raised do
Person.connection.add_column "people", "data", :string, :default => ''
Person.connection.change_column "people", "data", :binary
end
end

def test_change_column_quotes_column_names
Person.connection.create_table :testings do |t|
t.column :select, :string
Expand Down

0 comments on commit ddadcc7

Please sign in to comment.