summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluca-landa <lucalanda@hotmail.it>2021-03-23 18:03:54 +0100
committerluca-landa <lucalanda@hotmail.it>2021-03-25 18:17:09 +0100
commit9ffa0abb99aa91ea4ac8b3ddbfd30a6a149a947d (patch)
tree7ca91acd6a8d2775b9ca57609f868357ae6db7a9
parentaf29cabe832c06adef993057c03451a3859dcf84 (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.rb22
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