diff --git a/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb b/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb index 3ed6048390d..cd50bd414fc 100644 --- a/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb +++ b/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb @@ -21,15 +21,28 @@ def up StoreCreditReason.create!(name: update_reason.name) end - drop_table :spree_store_credit_update_reasons - rename_column :spree_store_credit_events, :update_reason_id, :store_credit_reason_id + add_column :spree_store_credit_events, :store_credit_reason_id, :integer + execute "update spree_store_credit_events set store_credit_reason_id = update_reason_id" + + # TODO: table spree_store_credit_update_reasons and column + # column spree_store_credit_update_reasons.update_reason_id + # must be dropped in a future Solidus release end def down - create_table :spree_store_credit_update_reasons do |t| - t.string :name - - t.timestamps + # This table and column may not exist anymore as another irreversible + # migration may have removed it later. They must be added back or the + # `up` method would fail + unless table_exists? :spree_store_credit_update_reasons + create_table :spree_store_credit_update_reasons do |t| + t.string :name + + t.timestamps + end + + unless column_exists? :spree_store_credit_events, :update_reason_id + add_column :spree_store_credit_events, :update_reason_id, :integer + end end StoreCreditReason.all.each do |store_credit_reason| @@ -37,6 +50,6 @@ def down end drop_table :spree_store_credit_reasons - rename_column :spree_store_credit_events, :store_credit_reason_id, :update_reason_id + remove_column :spree_store_credit_events, :store_credit_reason_id end end