This project is archived and is in readonly mode.

#2741 ✓committed
Giles Alexander

Decimal column with zero scale dumped as integer column

Reported by Giles Alexander | May 30th, 2009 @ 09:13 AM | in 2.x

If you declare a decimal column with a scale of 0 in a migration:

create_table :large_integers do |t|
  t.decimal :large, :scale => 0, :precision => 80

  t.timestamps
end

Then a table will be created like the following:

large      | numeric(40,0)               |
created_at | timestamp without time zone | 
updated_at | timestamp without time zone |

But, after running rake db:schema:dump, db/schema.rb will contain something like the following:

create_table "large_integers", :force => true do |t|
  t.integer  "large",      :limit => 80, :precision => 80, :scale => 0
  t.datetime "created_at"
  t.datetime "updated_at"
end

On PostgreSQL, this will create an integer column, not a numeric column, and if the precision is large then the column can not hold numbers up to that precision.

Plus, it is a little surprising to have schema.rb differing from your migration like this.

The attached patch fixes this problem in the schema dumper by looking for integer columns where the underlying sql_type is decimal or numeric, and then setting the type to be emitted to 'decimal' instead of 'integer'.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages