mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Set master variants which are associated to line items to non-master
Line items which reference a master variant is a scenario that in theory shouldn't have been valid or even possible for at least 5-6 years, and these old bits of data in theory should have been cleaned up at the time those changes were made. But a couple of servers have some really old data that's not in a nice state. Here we can just flip the is_master flag to false for those specific (legacy data) cases before deleting any other master variants, to keep the legacy line item data intact.
This commit is contained in:
@@ -4,7 +4,7 @@ class RemoveMasterVariants < ActiveRecord::Migration[7.0]
|
||||
delete_master_option_values
|
||||
end
|
||||
|
||||
delete_master_line_items
|
||||
handle_master_line_items
|
||||
delete_master_inventory_units
|
||||
delete_master_variant_prices
|
||||
delete_master_variants
|
||||
@@ -12,10 +12,11 @@ class RemoveMasterVariants < ActiveRecord::Migration[7.0]
|
||||
|
||||
private
|
||||
|
||||
def delete_master_line_items
|
||||
def handle_master_line_items
|
||||
ActiveRecord::Base.connection.execute(<<-SQL
|
||||
DELETE FROM spree_line_items
|
||||
USING spree_variants
|
||||
UPDATE spree_variants
|
||||
SET is_master = false
|
||||
FROM spree_line_items
|
||||
WHERE spree_variants.is_master = true
|
||||
AND spree_variants.id = spree_line_items.variant_id
|
||||
SQL
|
||||
|
||||
Reference in New Issue
Block a user