From 9f0c1ed464a9c91a094149e9ea26acf9ae10591e Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 26 Jul 2025 17:00:08 +0200 Subject: [PATCH 1/2] FK Migrations: Match on Exception names When migrating the database in a Solidus context, we usually only have the database adapter loaded that is being used. Rescuing exceptions from other adapters will therefore fail with an "uninitialized constant error". In order to safeguard from this, this commit changes the matching on error class to matching on their name. --- .../migrate/20250530102541_add_addressbook_foreign_key.rb | 5 +++-- ...250604072105_add_fk_products_variant_property_rules.rb | 4 +++- .../20250604072555_add_fk_to_product_properties.rb | 6 ++++-- .../20250604072948_add_fk_to_product_option_types.rb | 6 ++++-- .../migrate/20250604073219_add_fk_to_classifications.rb | 6 ++++-- .../20250605105424_add_shipping_category_foreign_keys.rb | 8 +++++--- .../20250626112117_add_foreign_key_to_spree_role_users.rb | 4 +++- .../20250708120317_add_adjustment_reason_foreign_keys.rb | 4 +++- 8 files changed, 29 insertions(+), 14 deletions(-) diff --git a/core/db/migrate/20250530102541_add_addressbook_foreign_key.rb b/core/db/migrate/20250530102541_add_addressbook_foreign_key.rb index 01f160dd11..d252ab1bee 100644 --- a/core/db/migrate/20250530102541_add_addressbook_foreign_key.rb +++ b/core/db/migrate/20250530102541_add_addressbook_foreign_key.rb @@ -1,16 +1,17 @@ # 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_user_addresses => :spree_addresses. To fix this: diff --git a/core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb b/core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb index 472de0a6a8..3e65156dcb 100644 --- a/core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb +++ b/core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb @@ -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 # @@ -10,7 +12,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_variant_property_rules => :spree_products. To fix this: diff --git a/core/db/migrate/20250604072555_add_fk_to_product_properties.rb b/core/db/migrate/20250604072555_add_fk_to_product_properties.rb index 92ec81d0ed..7cc7baaf3f 100644 --- a/core/db/migrate/20250604072555_add_fk_to_product_properties.rb +++ b/core/db/migrate/20250604072555_add_fk_to_product_properties.rb @@ -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 # @@ -10,7 +12,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_products. To fix this: @@ -30,7 +32,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_properties. To fix this: diff --git a/core/db/migrate/20250604072948_add_fk_to_product_option_types.rb b/core/db/migrate/20250604072948_add_fk_to_product_option_types.rb index 60df7a375d..70848a48fb 100644 --- a/core/db/migrate/20250604072948_add_fk_to_product_option_types.rb +++ b/core/db/migrate/20250604072948_add_fk_to_product_option_types.rb @@ -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 # @@ -10,7 +12,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_product_option_types => :spree_products. To fix this: @@ -30,7 +32,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_product_option_types => :spree_option_types. To fix this: diff --git a/core/db/migrate/20250604073219_add_fk_to_classifications.rb b/core/db/migrate/20250604073219_add_fk_to_classifications.rb index b81c34169f..5ed4e8a724 100644 --- a/core/db/migrate/20250604073219_add_fk_to_classifications.rb +++ b/core/db/migrate/20250604073219_add_fk_to_classifications.rb @@ -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 # @@ -10,7 +12,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_products. To fix this: @@ -30,7 +32,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_taxons. To fix this: diff --git a/core/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb b/core/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb index 9bdda77e2f..e40c77c380 100644 --- a/core/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb +++ b/core/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb @@ -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 # @@ -10,7 +12,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_products => :spree_shipping_categories. To fix this: @@ -30,7 +32,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_shipping_method_categories => :spree_shipping_methods. To fix this: @@ -50,7 +52,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_shipping_method_categories => :spree_shipping_categories. To fix this: diff --git a/core/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb b/core/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb index e331684a6d..256210ee66 100644 --- a/core/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb +++ b/core/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb @@ -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 # @@ -10,7 +12,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_roles_users => :spree_roles. To fix this: diff --git a/core/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb b/core/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb index e0eac2f8a9..9e0f42d00e 100644 --- a/core/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb +++ b/core/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb @@ -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 # @@ -10,7 +12,7 @@ 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) + if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) Rails.logger.warn <<~MSG ⚠️ Foreign key constraint failed when adding :spree_adjustments => :spree_adjustment_reasons. To fix this: From 707590cb71949fb9e24673b9b26730a3f703db34 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 26 Jul 2025 17:03:17 +0200 Subject: [PATCH 2/2] FK migration exception handling: Use "say" The standard way of producing output for users to read in a migration is `ActiveRecord::Migration#say`. --- .../migrate/20250530102541_add_addressbook_foreign_key.rb | 2 +- ...20250604072105_add_fk_products_variant_property_rules.rb | 2 +- .../migrate/20250604072555_add_fk_to_product_properties.rb | 4 ++-- .../20250604072948_add_fk_to_product_option_types.rb | 4 ++-- core/db/migrate/20250604073219_add_fk_to_classifications.rb | 4 ++-- .../20250605105424_add_shipping_category_foreign_keys.rb | 6 +++--- .../20250626112117_add_foreign_key_to_spree_role_users.rb | 2 +- .../20250708120317_add_adjustment_reason_foreign_keys.rb | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/db/migrate/20250530102541_add_addressbook_foreign_key.rb b/core/db/migrate/20250530102541_add_addressbook_foreign_key.rb index d252ab1bee..b5112675e7 100644 --- a/core/db/migrate/20250530102541_add_addressbook_foreign_key.rb +++ b/core/db/migrate/20250530102541_add_addressbook_foreign_key.rb @@ -12,7 +12,7 @@ def up add_foreign_key :spree_user_addresses, :spree_addresses, column: :address_id, null: false rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + say <<~MSG ⚠️ Foreign key constraint failed when adding :spree_user_addresses => :spree_addresses. To fix this: 1. Uncomment the code that removes orphaned records. diff --git a/core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb b/core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb index 3e65156dcb..2e9e7b31c6 100644 --- a/core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb +++ b/core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb @@ -13,7 +13,7 @@ def up add_foreign_key :spree_variant_property_rules, :spree_products, column: :product_id, null: false rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + 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. diff --git a/core/db/migrate/20250604072555_add_fk_to_product_properties.rb b/core/db/migrate/20250604072555_add_fk_to_product_properties.rb index 7cc7baaf3f..ac02aa0441 100644 --- a/core/db/migrate/20250604072555_add_fk_to_product_properties.rb +++ b/core/db/migrate/20250604072555_add_fk_to_product_properties.rb @@ -13,7 +13,7 @@ def up add_foreign_key :spree_product_properties, :spree_products, column: :product_id, null: false rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + say <<~MSG ⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_products. To fix this: 1. Uncomment the code that removes orphaned records. @@ -33,7 +33,7 @@ def up add_foreign_key :spree_product_properties, :spree_properties, column: :property_id, null: false rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + say <<~MSG ⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_properties. To fix this: 1. Uncomment the code that removes orphaned records. diff --git a/core/db/migrate/20250604072948_add_fk_to_product_option_types.rb b/core/db/migrate/20250604072948_add_fk_to_product_option_types.rb index 70848a48fb..05fa6004f0 100644 --- a/core/db/migrate/20250604072948_add_fk_to_product_option_types.rb +++ b/core/db/migrate/20250604072948_add_fk_to_product_option_types.rb @@ -13,7 +13,7 @@ def up add_foreign_key :spree_product_option_types, :spree_products, column: :product_id rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + 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. @@ -33,7 +33,7 @@ def up add_foreign_key :spree_product_option_types, :spree_option_types, column: :option_type_id rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + 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. diff --git a/core/db/migrate/20250604073219_add_fk_to_classifications.rb b/core/db/migrate/20250604073219_add_fk_to_classifications.rb index 5ed4e8a724..f8519eed06 100644 --- a/core/db/migrate/20250604073219_add_fk_to_classifications.rb +++ b/core/db/migrate/20250604073219_add_fk_to_classifications.rb @@ -13,7 +13,7 @@ def up add_foreign_key :spree_products_taxons, :spree_products, column: :product_id rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + say <<~MSG ⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_products. To fix this: 1. Uncomment the code that removes orphaned records. @@ -33,7 +33,7 @@ def up add_foreign_key :spree_products_taxons, :spree_taxons, column: :taxon_id rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + say <<~MSG ⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_taxons. To fix this: 1. Uncomment the code that removes orphaned records. diff --git a/core/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb b/core/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb index e40c77c380..910eca3d2a 100644 --- a/core/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb +++ b/core/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb @@ -13,7 +13,7 @@ def change add_foreign_key :spree_products, :spree_shipping_categories, column: :shipping_category_id, null: false rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + say <<~MSG ⚠️ Foreign key constraint failed when adding :spree_products => :spree_shipping_categories. To fix this: 1. Uncomment the code that removes orphaned records. @@ -33,7 +33,7 @@ def change add_foreign_key :spree_shipping_method_categories, :spree_shipping_methods, column: :shipping_method_id, null: false rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + 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. @@ -53,7 +53,7 @@ def change add_foreign_key :spree_shipping_method_categories, :spree_shipping_categories, column: :shipping_category_id, null: false rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + 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. diff --git a/core/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb b/core/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb index 256210ee66..da61e7a932 100644 --- a/core/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb +++ b/core/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb @@ -13,7 +13,7 @@ def up add_foreign_key :spree_roles_users, :spree_roles, column: :role_id, null: false rescue ActiveRecord::StatementInvalid => e if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + say <<~MSG ⚠️ Foreign key constraint failed when adding :spree_roles_users => :spree_roles. To fix this: 1. Uncomment the code that removes orphaned records. diff --git a/core/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb b/core/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb index 9e0f42d00e..f7311426b0 100644 --- a/core/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb +++ b/core/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb @@ -13,7 +13,7 @@ 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.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS) - Rails.logger.warn <<~MSG + 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.