diff --git a/lib/solidus_friendly_promotions/migrate_adjustments.rb b/lib/solidus_friendly_promotions/migrate_adjustments.rb index ee6cfcad..c27c4916 100644 --- a/lib/solidus_friendly_promotions/migrate_adjustments.rb +++ b/lib/solidus_friendly_promotions/migrate_adjustments.rb @@ -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