Skip to content

Commit

Permalink
Merge pull request #3109 from nebulab/spaghetticode/safer-migration-2…
Browse files Browse the repository at this point in the history
…0180710170104

Remove destructive actions from migration 20180710170104
  • Loading branch information
kennyadsl authored Feb 20, 2019
2 parents ea37b2a + da25ae7 commit e16106f
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,35 @@ 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|
StoreCreditUpdateReason.create!(name: store_credit_reason.name)
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

0 comments on commit e16106f

Please sign in to comment.