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

Changeset 4340

Show
Ignore:
Timestamp:
05/14/06 18:37:22 (2 years ago)
Author:
marcel
Message:

Preserve MySQL boolean column defaults when changing a column in a migration. Closes #5015. [pdcawley@bofh.org.uk]

Files:

Legend:

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

    r4335 r4340  
    11*SVN* 
     2 
     3* Preserve MySQL boolean column defaults when changing a column in a migration. Closes #5015. [pdcawley@bofh.org.uk]  
    24 
    35* PostgreSQL: migrations support :limit with :integer columns by mapping limit < 4 to smallint, > 4 to bigint, and anything else to integer. #2900 [keegan@thebasement.org] 
  • trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    r4239 r4340  
    309309 
    310310      def change_column(table_name, column_name, type, options = {}) #:nodoc: 
    311         options[:default] ||= select_one("SHOW COLUMNS FROM #{table_name} LIKE '#{column_name}'")["Default"] 
     311        if options[:default].nil? 
     312          options[:default] = select_one("SHOW COLUMNS FROM #{table_name} LIKE '#{column_name}'")["Default"] 
     313        end 
    312314         
    313315        change_column_sql = "ALTER TABLE #{table_name} CHANGE #{column_name} #{column_name} #{type_to_sql(type, options[:limit])}" 
  • trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb

    r4239 r4340  
    244244            self.type    = type 
    245245            self.limit   = options[:limit] if options[:limit] 
    246             self.default = options[:default] if options[:default] 
     246            self.default = options[:default] unless options[:default].nil? 
    247247          end 
    248248        end 
  • trunk/activerecord/test/migration_test.rb

    r4338 r4340  
    11require 'abstract_unit' 
    22require 'fixtures/person' 
     3require 'fixtures/topic' 
    34require File.dirname(__FILE__) + '/fixtures/migrations/1_people_have_last_names' 
    45require File.dirname(__FILE__) + '/fixtures/migrations/2_we_need_reminders' 
     
    321322      assert_nil new_columns.find { |c| c.name == 'age' and c.type == :integer } 
    322323      assert new_columns.find { |c| c.name == 'age' and c.type == :string } 
     324 
     325      old_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns") 
     326      assert old_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true } 
     327      assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => false } 
     328      new_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns") 
     329      assert_nil new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true } 
     330      assert new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == false } 
    323331    end     
    324332