diff --git a/core/db/migrate/20231027084517_add_order_promotions_foreign_key.rb b/core/db/migrate/20231027084517_add_order_promotions_foreign_key.rb new file mode 100644 index 00000000000..ef9e3cb5643 --- /dev/null +++ b/core/db/migrate/20231027084517_add_order_promotions_foreign_key.rb @@ -0,0 +1,10 @@ +class AddOrderPromotionsForeignKey < ActiveRecord::Migration[7.0] + def up + Spree::OrderPromotion.left_joins(:order).where(spree_orders: {id: nil}).delete_all + add_foreign_key :spree_orders_promotions, :spree_orders, column: :order_id, validate: false, on_delete: :cascade + end + + def down + remove_foreign_key :spree_orders_promotions, :spree_orders + end +end