Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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  
    268268      Person.reset_column_information 
    269269    end 
    270270 
     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     
    271280    def test_native_types 
    272281      Person.delete_all 
    273282      Person.connection.add_column "people", "last_name", :string 
  • activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

    old new  
    574574        execute "ALTER TABLE #{name} RENAME TO #{new_name}" 
    575575      end 
    576576 
    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. 
    578579      def add_column(table_name, column_name, type, options = {}) 
    579580        default = options[:default] 
    580581        notnull = options[:null] == false 
     
    582583        quoted_column_name = quote_column_name(column_name) 
    583584 
    584585        # 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])}") 
    586587 
    587588        # Set optional default. If not null, update nulls to the new default. 
    588589        if options_include_default?(options)