diff options
author | luca-landa <lucalanda@hotmail.it> | 2021-03-23 18:03:54 +0100 |
---|---|---|
committer | luca-landa <lucalanda@hotmail.it> | 2021-03-25 18:17:09 +0100 |
commit | 9ffa0abb99aa91ea4ac8b3ddbfd30a6a149a947d (patch) | |
tree | 7ca91acd6a8d2775b9ca57609f868357ae6db7a9 | |
parent | af29cabe832c06adef993057c03451a3859dcf84 (diff) |
Update promotion rule names on db
After
https://github.com/solidusio-contrib/solidus_subscriptions/pull/215
update promotion rule names on db to avoid STI errors.
-rw-r--r-- | db/migrate/20210323165714_update_promotion_rule_names.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/db/migrate/20210323165714_update_promotion_rule_names.rb b/db/migrate/20210323165714_update_promotion_rule_names.rb new file mode 100644 index 0000000..f6ee6c2 --- /dev/null +++ b/db/migrate/20210323165714_update_promotion_rule_names.rb @@ -0,0 +1,22 @@ +class UpdatePromotionRuleNames < ActiveRecord::Migration[5.2] + TYPE_RENAMES = { + 'SolidusSubscriptions::SubscriptionPromotionRule' => 'SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder', + 'SolidusSubscriptions::SubscriptionOrderPromotionRule' => 'SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder', + }.freeze + + def change + reversible do |dir| + dir.up do + TYPE_RENAMES.each do |old_type, new_type| + Spree::PromotionRule.where(type: old_type).update(type: new_type) + end + end + + dir.down do + TYPE_RENAMES.each do |old_type, new_type| + Spree::PromotionRule.where(type: new_type).update(type: old_type) + end + end + end + end +end |