From 9095abfed27e86e2f44e37f6ea334c5c22a1e59a Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 5 Jun 2023 15:11:50 +0100 Subject: [PATCH] Delete master variants (cherry picked from commit b59bdc75e957291c015743d8420840c790dfe5d7) --- .../20230605133804_remove_master_variants.rb | 40 +++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230605133804_remove_master_variants.rb diff --git a/db/migrate/20230605133804_remove_master_variants.rb b/db/migrate/20230605133804_remove_master_variants.rb new file mode 100644 index 0000000000..23b79a9014 --- /dev/null +++ b/db/migrate/20230605133804_remove_master_variants.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 6d00733f5b..361d806e11 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"