Question

create_table "spree_prices", force: true do |t|
    t.integer  "variant_id",                         null: false
    t.decimal  "amount",     precision: 8, scale: 2
    t.string   "currency"
    t.datetime "deleted_at"
  end

In the schema generated by Spree, the price is only allocated 8 precision with 2 scale. It disallow price >= 1,000,000 which is common in non USD currency.

1) What is the best way to overcome this? Creating new migration which change the datatype? Or modify the existing migrations? Or something else?

2) If later I want to upgrade Spree, would the change impact the upgrading process?

Was it helpful?

Solution

1) What is the best way to overcome this? Creating new migration which change the datatype? Or modify the existing migrations? Or something else?

Yes the best way is to add new migration, which is the whole purpose of migration, to maintain different versions of schema. If you update the older schema migrations, It wont affect if you have already ran this migration in the system, only new migration is the best practice solution.

Have a look at this and this.

In general, editing existing migrations is not a good idea. You will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead, you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or, more generally, which has not been propagated beyond your development machine) is relatively harmless.

2) If later I want to upgrade Spree, would the change impact the upgrading process?

That is little difficult to say for me, as I dont have such experience, if in latest version of spree, that have only upgraded the migration, in that case, you will have to just remove that particular migration, as you would have already incorporated that already.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top