Skip to content

Commit

Permalink
Fix sql for mysql MigrateAdjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
davecandlescience committed Oct 26, 2023
1 parent b1f4d07 commit 3b5bd5a
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions lib/solidus_friendly_promotions/migrate_adjustments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,48 @@ module SolidusFriendlyPromotions
class MigrateAdjustments
class << self
def up
sql = <<~SQL
UPDATE spree_adjustments
SET source_id = friendly_promotion_actions.id,
source_type = 'SolidusFriendlyPromotions::PromotionAction'
sql = if ActiveRecord::Base.connection_db_config.adapter == "mysql2"
<<~SQL
UPDATE spree_adjustments
INNER JOIN spree_promotion_actions ON spree_adjustments.source_id = spree_promotion_actions.id and spree_adjustments.source_type = 'Spree::PromotionAction'
INNER JOIN friendly_promotion_actions ON friendly_promotion_actions.original_promotion_action_id = spree_promotion_actions.id
SET source_id = friendly_promotion_actions.id,
source_type = 'SolidusFriendlyPromotions::PromotionAction'
SQL
else
<<~SQL
UPDATE spree_adjustments
SET source_id = friendly_promotion_actions.id,
source_type = 'SolidusFriendlyPromotions::PromotionAction'
FROM spree_promotion_actions
INNER JOIN friendly_promotion_actions ON friendly_promotion_actions.original_promotion_action_id = spree_promotion_actions.id
INNER JOIN friendly_promotion_actions ON friendly_promotion_actions.original_promotion_action_id = spree_promotion_actions.id
WHERE spree_adjustments.source_id = spree_promotion_actions.id and spree_adjustments.source_type = 'Spree::PromotionAction'
SQL
SQL
end

execute(sql)
end

def down
sql = <<~SQL
UPDATE spree_adjustments
SET source_id = spree_promotion_actions.id,
source_type = 'Spree::PromotionAction'
sql = if ActiveRecord::Base.connection_db_config.adapter == "mysql2"
<<~SQL
UPDATE spree_adjustments
INNER JOIN friendly_promotion_actions
INNER JOIN spree_promotion_actions ON spree_adjustments.source_id = friendly_promotion_actions.id and spree_adjustments.source_type = 'SolidusFriendlyPromotions::PromotionAction'
SET source_id = spree_promotion_actions.id,
source_type = 'Spree::PromotionAction'
WHERE friendly_promotion_actions.original_promotion_action_id = spree_promotion_actions.id
SQL
else
<<~SQL
UPDATE spree_adjustments
SET source_id = spree_promotion_actions.id,
source_type = 'Spree::PromotionAction'
FROM spree_promotion_actions
INNER JOIN friendly_promotion_actions ON friendly_promotion_actions.original_promotion_action_id = spree_promotion_actions.id
INNER JOIN friendly_promotion_actions ON friendly_promotion_actions.original_promotion_action_id = spree_promotion_actions.id
WHERE spree_adjustments.source_id = friendly_promotion_actions.id and spree_adjustments.source_type = 'SolidusFriendlyPromotions::PromotionAction'
SQL
SQL
end

execute(sql)
end
Expand Down

0 comments on commit 3b5bd5a

Please sign in to comment.