Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/db/migrate/20250530102541_add_addressbook_foreign_key.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# frozen_string_literal: true

class AddAddressbookForeignKey < ActiveRecord::Migration[7.0]
FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]

def up
# Uncomment the following code to remove orphaned records if this migration fails
#
# say_with_time "Removing orphaned address book entries (no corresponding address)" do
# Spree::UserAddress.left_joins(:address).where(spree_addresses: { id: nil }).delete_all
# end

add_foreign_key :spree_user_addresses, :spree_addresses, column: :address_id, null: false
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_user_addresses => :spree_addresses.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class AddFkProductsVariantPropertyRules < ActiveRecord::Migration[7.0]
FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]

def up
# Uncomment the following code to remove orphaned records if this migration fails
#
Expand All @@ -10,8 +12,8 @@ def up

add_foreign_key :spree_variant_property_rules, :spree_products, column: :product_id, null: false
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_variant_property_rules => :spree_products.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand Down
10 changes: 6 additions & 4 deletions core/db/migrate/20250604072555_add_fk_to_product_properties.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class AddFkToProductProperties < ActiveRecord::Migration[7.0]
FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]

def up
# Uncomment the following code to remove orphaned records if this migration fails
#
Expand All @@ -10,8 +12,8 @@ def up
begin
add_foreign_key :spree_product_properties, :spree_products, column: :product_id, null: false
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_products.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand All @@ -30,8 +32,8 @@ def up
begin
add_foreign_key :spree_product_properties, :spree_properties, column: :property_id, null: false
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_properties.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand Down
10 changes: 6 additions & 4 deletions core/db/migrate/20250604072948_add_fk_to_product_option_types.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class AddFkToProductOptionTypes < ActiveRecord::Migration[7.0]
FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]

def up
# Uncomment the following code to remove orphaned records if this migration fails
#
Expand All @@ -10,8 +12,8 @@ def up
begin
add_foreign_key :spree_product_option_types, :spree_products, column: :product_id
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_product_option_types => :spree_products.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand All @@ -30,8 +32,8 @@ def up
begin
add_foreign_key :spree_product_option_types, :spree_option_types, column: :option_type_id
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_product_option_types => :spree_option_types.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand Down
10 changes: 6 additions & 4 deletions core/db/migrate/20250604073219_add_fk_to_classifications.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class AddFkToClassifications < ActiveRecord::Migration[7.0]
FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]

def up
# Uncomment the following code to remove orphaned records if this migration fails
#
Expand All @@ -10,8 +12,8 @@ def up
begin
add_foreign_key :spree_products_taxons, :spree_products, column: :product_id
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_products.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand All @@ -30,8 +32,8 @@ def up
begin
add_foreign_key :spree_products_taxons, :spree_taxons, column: :taxon_id
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_taxons.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class AddShippingCategoryForeignKeys < ActiveRecord::Migration[7.0]
FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]

def change
# Uncomment the following code to remove orphaned records if the following code fails
#
Expand All @@ -10,8 +12,8 @@ def change
begin
add_foreign_key :spree_products, :spree_shipping_categories, column: :shipping_category_id, null: false
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_products => :spree_shipping_categories.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand All @@ -30,8 +32,8 @@ def change
begin
add_foreign_key :spree_shipping_method_categories, :spree_shipping_methods, column: :shipping_method_id, null: false
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_shipping_method_categories => :spree_shipping_methods.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand All @@ -50,8 +52,8 @@ def change
begin
add_foreign_key :spree_shipping_method_categories, :spree_shipping_categories, column: :shipping_category_id, null: false
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_shipping_method_categories => :spree_shipping_categories.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class AddForeignKeyToSpreeRoleUsers < ActiveRecord::Migration[7.0]
FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]

def up
# Uncomment the following code to remove orphaned records if this migration fails
#
Expand All @@ -10,8 +12,8 @@ def up

add_foreign_key :spree_roles_users, :spree_roles, column: :role_id, null: false
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_roles_users => :spree_roles.
To fix this:
1. Uncomment the code that removes orphaned records.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class AddAdjustmentReasonForeignKeys < ActiveRecord::Migration[7.0]
FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]

def up
# Uncomment the following code to remove orphaned records if this migration fails
#
Expand All @@ -10,8 +12,8 @@ def up

add_foreign_key :spree_adjustments, :spree_adjustment_reasons, column: :adjustment_reason_id, null: true, on_delete: :restrict
rescue ActiveRecord::StatementInvalid => e
if e.cause.is_a?(PG::ForeignKeyViolation) || e.cause.is_a?(Mysql2::Error) || e.cause.is_a?(SQLite3::ConstraintException)
Rails.logger.warn <<~MSG
if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
say <<~MSG
⚠️ Foreign key constraint failed when adding :spree_adjustments => :spree_adjustment_reasons.
To fix this:
1. Uncomment the code that removes invalid adjustment reason IDs from the spree_adjustments table.
Expand Down
Loading