From 9ffa0abb99aa91ea4ac8b3ddbfd30a6a149a947d Mon Sep 17 00:00:00 2001 From: luca-landa Date: Tue, 23 Mar 2021 18:03:54 +0100 Subject: 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. --- .../20210323165714_update_promotion_rule_names.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 db/migrate/20210323165714_update_promotion_rule_names.rb 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 -- cgit v1.2.3