Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5935

Show
Ignore:
Timestamp:
01/15/07 01:24:23 (2 years ago)
Author:
bitsweat
Message:

MySQL, PostgreSQL: change_column_default quotes the default value and doesn't lose column type information. References #3987, closes #6664.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r5933 r5935  
    11*SVN* 
     2 
     3* MySQL, PostgreSQL: change_column_default quotes the default value and doesn't lose column type information.  #3987, #6664 [Jonathan Viney, manfred, altano@bigfoot.com] 
    24 
    35* Oracle: create_table takes a :sequence_name option to override the 'tablename_seq' default.  #7000 [Michael Schoen] 
  • trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    r5929 r5935  
    361361        current_type = select_one("SHOW COLUMNS FROM #{table_name} LIKE '#{column_name}'")["Type"] 
    362362 
    363         change_column(table_name, column_name, current_type, { :default => default }
     363        execute("ALTER TABLE #{table_name} CHANGE #{column_name} #{column_name} #{current_type} DEFAULT #{quote(default)}"
    364364      end 
    365365 
  • trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

    r5887 r5935  
    350350 
    351351      def change_column_default(table_name, column_name, default) #:nodoc: 
    352         execute "ALTER TABLE #{table_name} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT '#{default}'
     352        execute "ALTER TABLE #{table_name} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{quote(default)}
    353353      end 
    354354 
  • trunk/activerecord/test/migration_test.rb

    r5933 r5935  
    426426 
    427427    def test_change_column_with_new_default 
    428       Person.connection.add_column "people", "administrator", :boolean, :default => 1 
     428      Person.connection.add_column "people", "administrator", :boolean, :default => true 
    429429      Person.reset_column_information 
    430430      assert Person.new.administrator? 
    431431 
    432       assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => 0
     432      assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => false
    433433      Person.reset_column_information 
    434434      assert !Person.new.administrator? 
     435    end 
     436     
     437    def test_change_column_default 
     438      Person.connection.change_column_default "people", "first_name", "Tester" 
     439      Person.reset_column_information 
     440      assert_equal "Tester", Person.new.first_name 
     441    end 
     442     
     443    def test_change_column_default_to_null 
     444      Person.connection.change_column_default "people", "first_name", nil 
     445      Person.reset_column_information 
     446      assert_nil Person.new.first_name 
    435447    end 
    436448