From a92bbdf12656346f87fb33ef9a09426184f577db Mon Sep 17 00:00:00 2001 From: taryn Date: Wed, 22 Jul 2009 12:14:26 +0100 Subject: [PATCH] A test that successfully reproduces the precision/scale error in SQLite - along with the patch from Andrey Zaikin that fixes it --- .../connection_adapters/sqlite_adapter.rb | 2 ++ activerecord/test/cases/migration_test.rb | 20 ++++++++++++++++++++ 2 files changed, 22 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 5e5e307..61ee470 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -295,6 +295,8 @@ module ActiveRecord self.type = type self.limit = options[:limit] if options.include?(:limit) self.default = options[:default] if include_default + self.precision = options[:precision] if options.include?(:precision) + self.scale = options[:scale] if options.include?(:scale) self.null = options[:null] if options.include?(:null) end end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 215b5a4..61173cb 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -770,6 +770,26 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.remove_column("people", "administrator") rescue nil end + if current_adapter?(:SQLiteAdapter) + def test_change_column_adding_precision_and_scale + # first add a column without any precision/scale + Person.connection.add_column "people", "my_decimal", :decimal + Person.reset_column_information + + new_columns = Person.connection.columns(Person.table_name, "#{name} Columns") + assert(new_columns.find { |c| c.name == 'my_decimal' && c.type == :decimal && c.scale.nil? && c.precision.nil? }, "should have found a decimal column with nil precision and scale") + + # now try to change the column by adding a precision/scale + assert_nothing_raised { Person.connection.change_column "people", "my_decimal", :decimal, :precision => 5, :scale => 2 } + Person.reset_column_information + + new_columns = Person.connection.columns(Person.table_name, "#{name} Columns") + assert(new_columns.find { |c| c.name == 'my_decimal' && c.type == :decimal && c.scale == 2 && c.precision == 5 }, "should now have found a decimal column with the given precision and scale") + ensure + Person.connection.remove_column("people", "my_decimal") rescue nil + end + end + def test_change_column_default Person.connection.change_column_default "people", "first_name", "Tester" Person.reset_column_information -- 1.6.0.4