I have to create a database schema with Rails migrations.
I have lots of columns which contain quantities (kg) and prices (currency).
Currently I use this:
t.column :quantity, :decimal, :precision => 6, :scale => 3
t.column :value, :decimal, :precision => 6, :scale => 2
At the generator call I use quantity:decimal
to identify my columns. Then I manually change the generated t.decimal
lines to the above.
I don't like this, because after every generated migration I manually have to edit the migration script and I worry about DRY. (What if the price has to contain four instead of two decimal places?)
Is it possible to create a custom column type which I can use in migrations and perhaps even generators, like this:
t.quantity :quantity
t.price :value
PS: I'm a Rails noob, I'm sorry if this is a stupid question.