Remove inventory units 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 17:20:28 +01:00
parent 24aa55e053
commit 6f5d3ceacc

View File

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