mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
preserve decimal column attributes after migration
This commit is contained in:
parent
79d01a8f16
commit
f092be821d
2 changed files with 39 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue