Changeset 4340
- Timestamp:
- 05/14/06 18:37:22 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb (modified) (1 diff)
- trunk/activerecord/test/migration_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r4335 r4340 1 1 *SVN* 2 3 * Preserve MySQL boolean column defaults when changing a column in a migration. Closes #5015. [pdcawley@bofh.org.uk] 2 4 3 5 * 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 309 309 310 310 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 312 314 313 315 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 244 244 self.type = type 245 245 self.limit = options[:limit] if options[:limit] 246 self.default = options[:default] if options[:default]246 self.default = options[:default] unless options[:default].nil? 247 247 end 248 248 end trunk/activerecord/test/migration_test.rb
r4338 r4340 1 1 require 'abstract_unit' 2 2 require 'fixtures/person' 3 require 'fixtures/topic' 3 4 require File.dirname(__FILE__) + '/fixtures/migrations/1_people_have_last_names' 4 5 require File.dirname(__FILE__) + '/fixtures/migrations/2_we_need_reminders' … … 321 322 assert_nil new_columns.find { |c| c.name == 'age' and c.type == :integer } 322 323 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 } 323 331 end 324 332