aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-10-21 16:49:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-10-21 16:49:21 -0700
commitd8b09f3866defcd1bc97717fcc1bbfe9f643bd8c (patch)
treefaade0dae95ebc78dda2d22d515f8a58c32bbb4a
parent79d01a8f16e20c556a086a2f07e3ccb4400f9819 (diff)
parentf092be821db4a2e8f142e8f0b9d08e497ccf2eb2 (diff)
downloadrails-d8b09f3866defcd1bc97717fcc1bbfe9f643bd8c.tar.gz
rails-d8b09f3866defcd1bc97717fcc1bbfe9f643bd8c.tar.bz2
rails-d8b09f3866defcd1bc97717fcc1bbfe9f643bd8c.zip
Merge pull request #3400 from greinacker/sqlite-decimal
sqlite3 adapter drops :decimal columns precision & scale when migration tries to alter them
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb3
-rw-r--r--activerecord/test/cases/migration_test.rb36
2 files changed, 39 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 1932a849ee..e0e957a12c 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -413,6 +413,8 @@ module ActiveRecord
self.limit = options[:limit] if options.include?(:limit)
self.default = options[:default] if include_default
self.null = options[:null] if options.include?(:null)
+ self.precision = options[:precision] if options.include?(:precision)
+ self.scale = options[:scale] if options.include?(:scale)
end
end
end
@@ -467,6 +469,7 @@ module ActiveRecord
@definition.column(column_name, column.type,
:limit => column.limit, :default => column.default,
+ :precision => column.precision, :scale => column.scale,
:null => column.null)
end
@definition.primary_key(primary_key(from)) if primary_key(from)
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index b3f1785f44..49944eced9 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -518,6 +518,42 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_equal 7, wealth_column.scale
end
+ # Test SQLite adapter specifically for decimal types with precision and scale
+ # attributes, since these need to be maintained in schema but aren't actually
+ # used in SQLite itself
+ if current_adapter?(:SQLite3Adapter)
+ def test_change_column_with_new_precision_and_scale
+ Person.delete_all
+ Person.connection.add_column 'people', 'wealth', :decimal, :precision => 9, :scale => 7
+ Person.reset_column_information
+
+ Person.connection.change_column 'people', 'wealth', :decimal, :precision => 12, :scale => 8
+ Person.reset_column_information
+
+ wealth_column = Person.columns_hash['wealth']
+ assert_equal 12, wealth_column.precision
+ assert_equal 8, wealth_column.scale
+ end
+
+ def test_change_column_preserve_other_column_precision_and_scale
+ Person.delete_all
+ Person.connection.add_column 'people', 'last_name', :string
+ Person.connection.add_column 'people', 'wealth', :decimal, :precision => 9, :scale => 7
+ Person.reset_column_information
+
+ wealth_column = Person.columns_hash['wealth']
+ assert_equal 9, wealth_column.precision
+ assert_equal 7, wealth_column.scale
+
+ Person.connection.change_column 'people', 'last_name', :string, :null => false
+ Person.reset_column_information
+
+ wealth_column = Person.columns_hash['wealth']
+ assert_equal 9, wealth_column.precision
+ assert_equal 7, wealth_column.scale
+ end
+ end
+
def test_native_types
Person.delete_all
Person.connection.add_column "people", "last_name", :string