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 authored and Astr0surf3r committed Nov 14, 2024
1 parent aab9aff commit 81ce9fe
Showing 1 changed file with 33 additions and 12 deletions.
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 81ce9fe

Please sign in to comment.