mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user