Remove line items related to master variants

These shouldn't technically exist, but apparently they can be present if the dataset is old enough. They can trigger a foreign key violation if they are present when a master variant is deleted, so they need to be dropped if present.
This commit is contained in:
Matt-Yorkley
2023-06-21 18:08:21 +01:00
parent 6f5d3ceacc
commit f9185ea56e

View File

@@ -4,6 +4,7 @@ class RemoveMasterVariants < ActiveRecord::Migration[7.0]
delete_master_option_values
end
delete_master_line_items
delete_master_inventory_units
delete_master_variant_prices
delete_master_variants
@@ -11,6 +12,16 @@ class RemoveMasterVariants < ActiveRecord::Migration[7.0]
private
def delete_master_line_items
ActiveRecord::Base.connection.execute(<<-SQL
DELETE FROM spree_line_items
USING spree_variants
WHERE spree_variants.is_master = true
AND spree_variants.id = spree_line_items.variant_id
SQL
)
end
def delete_master_inventory_units
ActiveRecord::Base.connection.execute(<<-SQL
DELETE FROM spree_inventory_units