Delete master variants

(cherry picked from commit b59bdc75e9)
This commit is contained in:
Matt-Yorkley
2023-06-05 15:11:50 +01:00
committed by David Cook
parent aa9fd682d8
commit 9095abfed2
2 changed files with 41 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
class RemoveMasterVariants < ActiveRecord::Migration[7.0]
def change
if ActiveRecord::Base.connection.table_exists? "spree_option_values_variants"
delete_master_option_values
end
delete_master_variant_prices
delete_master_variants
end
private
def delete_master_option_values
ActiveRecord::Base.connection.execute(<<-SQL
DELETE FROM spree_option_values_variants
USING spree_variants
WHERE spree_variants.is_master = true
AND spree_variants.id = spree_option_values_variants.variant_id
SQL
)
end
def delete_master_variant_prices
ActiveRecord::Base.connection.execute(<<-SQL
DELETE FROM spree_prices
USING spree_variants
WHERE spree_variants.is_master = true
AND spree_variants.id = spree_prices.variant_id
SQL
)
end
def delete_master_variants
ActiveRecord::Base.connection.execute(<<-SQL
DELETE FROM spree_variants
WHERE is_master = true
SQL
)
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_06_03_181837) do
ActiveRecord::Schema[7.0].define(version: 2023_06_05_133804) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"