Ticket #6868: postgresql_add_decimal_column_with_scale_and_precision_patch.diff
| File postgresql_add_decimal_column_with_scale_and_precision_patch.diff, 2.0 kB (added by w.piekutowski, 1 year ago) |
|---|
-
activerecord/test/migration_test.rb
old new 268 268 Person.reset_column_information 269 269 end 270 270 271 def test_add_column_with_precision_and_scale 272 Person.connection.add_column 'people', 'wealth', :decimal, :precision => 89, :scale => 79 273 Person.reset_column_information 274 275 wealth_column = Person.columns_hash['wealth'] 276 assert_equal 89, wealth_column.precision 277 assert_equal 79, wealth_column.scale 278 end 279 271 280 def test_native_types 272 281 Person.delete_all 273 282 Person.connection.add_column "people", "last_name", :string -
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
old new 574 574 execute "ALTER TABLE #{name} RENAME TO #{new_name}" 575 575 end 576 576 577 # Adds a column to a table. 577 # Adds a new column to the named table. 578 # See TableDefinition#column for details of the options you can use. 578 579 def add_column(table_name, column_name, type, options = {}) 579 580 default = options[:default] 580 581 notnull = options[:null] == false … … 582 583 quoted_column_name = quote_column_name(column_name) 583 584 584 585 # Add the column. 585 execute("ALTER TABLE #{table_name} ADD COLUMN #{quoted_column_name} #{type_to_sql(type, options[:limit] )}")586 execute("ALTER TABLE #{table_name} ADD COLUMN #{quoted_column_name} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}") 586 587 587 588 # Set optional default. If not null, update nulls to the new default. 588 589 if options_include_default?(options)