mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
40
db/migrate/20230605133804_remove_master_variants.rb
Normal file
40
db/migrate/20230605133804_remove_master_variants.rb
Normal 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
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user