solidus_core 4.5.1 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/jobs/spree/base_job.rb +12 -0
  4. data/app/jobs/spree/state_change_tracking_job.rb +32 -0
  5. data/app/models/concerns/spree/state_change_tracking.rb +26 -0
  6. data/app/models/concerns/spree/user_address_book.rb +24 -6
  7. data/app/models/concerns/spree/user_methods.rb +52 -14
  8. data/app/models/concerns/spree/user_reporting.rb +1 -1
  9. data/app/models/spree/address.rb +8 -2
  10. data/app/models/spree/adjustment_reason.rb +1 -1
  11. data/app/models/spree/calculator.rb +0 -2
  12. data/app/models/spree/carton.rb +7 -0
  13. data/app/models/spree/classification.rb +3 -3
  14. data/app/models/spree/core/state_machines/order/class_methods.rb +0 -16
  15. data/app/models/spree/core/state_machines/order.rb +1 -0
  16. data/app/models/spree/core/state_machines/payment.rb +1 -8
  17. data/app/models/spree/core/state_machines/shipment.rb +1 -8
  18. data/app/models/spree/country.rb +16 -5
  19. data/app/models/spree/customer_return.rb +1 -2
  20. data/app/models/spree/fulfilment_changer.rb +38 -11
  21. data/app/models/spree/inventory_unit.rb +1 -1
  22. data/app/models/spree/line_item.rb +3 -2
  23. data/app/models/spree/order.rb +5 -7
  24. data/app/models/spree/order_cancellations.rb +17 -20
  25. data/app/models/spree/order_shipping.rb +2 -9
  26. data/app/models/spree/order_taxation.rb +3 -2
  27. data/app/models/spree/order_updater.rb +11 -7
  28. data/app/models/spree/payment_method.rb +0 -1
  29. data/app/models/spree/product.rb +6 -5
  30. data/app/models/spree/product_option_type.rb +2 -2
  31. data/app/models/spree/product_property.rb +2 -2
  32. data/app/models/spree/role_user.rb +3 -3
  33. data/app/models/spree/shipment.rb +26 -12
  34. data/app/models/spree/shipping_category.rb +2 -2
  35. data/app/models/spree/shipping_method_category.rb +2 -2
  36. data/app/models/spree/state.rb +7 -4
  37. data/app/models/spree/stock/quantifier.rb +33 -9
  38. data/app/models/spree/stock_item.rb +1 -1
  39. data/app/models/spree/stock_location.rb +3 -2
  40. data/app/models/spree/store.rb +6 -0
  41. data/app/models/spree/store_credit.rb +3 -3
  42. data/app/models/spree/store_credit_event.rb +1 -1
  43. data/app/models/spree/tax_category.rb +1 -1
  44. data/app/models/spree/taxon.rb +0 -3
  45. data/app/models/spree/taxonomy.rb +2 -2
  46. data/app/models/spree/user_address.rb +4 -4
  47. data/app/models/spree/variant.rb +1 -1
  48. data/app/models/spree/variant_property_rule.rb +1 -1
  49. data/app/models/spree/variant_property_rule_condition.rb +1 -1
  50. data/app/models/spree/wallet_payment_source.rb +2 -2
  51. data/app/subscribers/spree/carton_shipped_mailer_subscriber.rb +30 -0
  52. data/app/subscribers/spree/order_cancel_mailer_subscriber.rb +21 -0
  53. data/app/subscribers/spree/order_confirmation_mailer_subscriber.rb +23 -0
  54. data/app/subscribers/spree/order_inventory_cancellation_mailer_subscriber.rb +27 -0
  55. data/app/subscribers/spree/order_mailer_subscriber.rb +8 -26
  56. data/app/subscribers/spree/reimbursement_mailer_subscriber.rb +20 -0
  57. data/config/locales/en.yml +9 -0
  58. data/db/migrate/20160101010000_solidus_one_four.rb +92 -0
  59. data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
  60. data/db/migrate/20250129061658_add_metadata_to_spree_resources.rb +1 -1
  61. data/db/migrate/20250214094207_add_reverse_charge_status_to_store.rb +8 -0
  62. data/db/migrate/20250225051308_add_vat_id_email_and_reverse_charge_status_to_addresses.rb +10 -0
  63. data/db/migrate/20250508145917_add_email_to_stock_locations.rb +5 -0
  64. data/db/migrate/20250530102541_add_addressbook_foreign_key.rb +29 -0
  65. data/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb +30 -0
  66. data/db/migrate/20250604072555_add_fk_to_product_properties.rb +52 -0
  67. data/db/migrate/20250604072948_add_fk_to_product_option_types.rb +52 -0
  68. data/db/migrate/20250604073219_add_fk_to_classifications.rb +52 -0
  69. data/db/migrate/20250605105424_add_shipping_category_foreign_keys.rb +73 -0
  70. data/db/migrate/20250626112117_add_foreign_key_to_spree_role_users.rb +30 -0
  71. data/db/migrate/20250628094037_change_countries_iso_to_unique.rb +9 -0
  72. data/db/migrate/20250708120317_add_adjustment_reason_foreign_keys.rb +30 -0
  73. data/db/migrate/20250709073151_add_country_foreign_keys.rb +75 -0
  74. data/db/migrate/20250709084513_add_state_foreign_keys.rb +30 -0
  75. data/db/migrate/20250726220709_add_fk_to_customer_return.rb +30 -0
  76. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
  77. data/lib/generators/spree/dummy/dummy_generator.rb +2 -1
  78. data/lib/generators/spree/dummy/templates/rails/{manifest.js → manifest.js.tt} +2 -0
  79. data/lib/spree/app_configuration.rb +8 -0
  80. data/lib/spree/core/engine.rb +7 -2
  81. data/lib/spree/core/environment.rb +1 -0
  82. data/lib/spree/core/version.rb +6 -10
  83. data/lib/spree/core.rb +2 -0
  84. data/lib/spree/permitted_attributes.rb +2 -1
  85. data/lib/spree/preferences/preferable.rb +1 -5
  86. data/lib/spree/testing_support/capybara_driver.rb +9 -0
  87. data/lib/spree/testing_support/common_rake.rb +6 -3
  88. data/lib/spree/testing_support/dummy_app/migrations.rb +2 -2
  89. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +0 -6
  90. data/lib/spree/testing_support/dummy_app.rb +7 -0
  91. data/lib/spree/testing_support/factories/zone_factory.rb +4 -0
  92. data/lib/spree/testing_support/job_helpers.rb +6 -15
  93. data/lib/spree/testing_support/translations.rb +2 -2
  94. data/lib/spree/zero.rb +3 -0
  95. data/solidus_core.gemspec +6 -2
  96. metadata +56 -5
  97. /data/{lib → app/models/concerns}/spree/preferences/persistable.rb +0 -0
@@ -1,35 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- # Mailing after events on a {Spree::Order}
5
4
  class OrderMailerSubscriber
6
5
  include Omnes::Subscriber
7
6
 
8
- handle :order_finalized,
9
- with: :send_confirmation_email,
10
- id: :spree_order_mailer_send_confirmation_email
7
+ def send_confirmation_email(_event) = nil
8
+ deprecate send_confirmation_email:
9
+ "Use Spree::OrderConfirmationMailerSubscriber#send_confirmation_email instead",
10
+ deprecator: Spree.deprecator
11
11
 
12
- handle :reimbursement_reimbursed,
13
- with: :send_reimbursement_email,
14
- id: :spree_order_mailer_send_reimbursement_email
15
-
16
- # Sends confirmation email to the user
17
- #
18
- # @param event [Omnes::UnstructuredEvent]
19
- def send_confirmation_email(event)
20
- order = event[:order]
21
- unless order.confirmation_delivered?
22
- Spree::Config.order_mailer_class.confirm_email(order).deliver_later
23
- order.update_column(:confirmation_delivered, true)
24
- end
25
- end
26
-
27
- # Sends reimbursement email to the user
28
- #
29
- # @param event [Omnes::UnstructuredEvent]
30
- def send_reimbursement_email(event)
31
- reimbursement = event[:reimbursement]
32
- Spree::Config.reimbursement_mailer_class.reimbursement_email(reimbursement.id).deliver_later
33
- end
12
+ def send_reimbursement_email(_event) = nil
13
+ deprecate send_reimbursement_email:
14
+ "use Spree::ReimbursementMailerSubscriber#send_reimbursement_email instead",
15
+ deprecator: Spree.deprecator
34
16
  end
35
17
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ # Mailing after a reimbursement is successful for a {Spree::Order}
5
+ class ReimbursementMailerSubscriber
6
+ include Omnes::Subscriber
7
+
8
+ handle :reimbursement_reimbursed,
9
+ with: :send_reimbursement_email,
10
+ id: :spree_order_mailer_send_reimbursement_email
11
+
12
+ # Sends reimbursement email to the user
13
+ #
14
+ # @param event [Omnes::UnstructuredEvent]
15
+ def send_reimbursement_email(event)
16
+ reimbursement = event[:reimbursement]
17
+ Spree::Config.reimbursement_mailer_class.reimbursement_email(reimbursement.id).deliver_later
18
+ end
19
+ end
20
+ end
@@ -24,8 +24,10 @@ en:
24
24
  address2: Street Address (cont'd)
25
25
  city: City
26
26
  company: Company
27
+ email: Email
27
28
  name: Name
28
29
  phone: Phone
30
+ vat_id: VAT-ID
29
31
  zipcode: Zip Code
30
32
  spree/adjustment:
31
33
  adjustable: Adjustable
@@ -433,8 +435,10 @@ en:
433
435
  weight: Weight
434
436
  width: Width
435
437
  spree/zone:
438
+ country_ids: Countries
436
439
  description: Description
437
440
  name: Name
441
+ state_ids: States
438
442
  errors:
439
443
  models:
440
444
  spree/address:
@@ -2092,6 +2096,10 @@ en:
2092
2096
  return_quantity: Return Quantity
2093
2097
  return_reasons: Return Reasons
2094
2098
  returned: Returned
2099
+ reverse_charge_statuses:
2100
+ disabled: Disabled
2101
+ enabled: Enabled
2102
+ not_validated: Not Validated
2095
2103
  review: Review
2096
2104
  risk: Risk
2097
2105
  risk_analysis: Risk Analysis
@@ -2355,6 +2363,7 @@ en:
2355
2363
  variant_to_add: Variant to add
2356
2364
  variant_to_be_received: Variant to be received
2357
2365
  variants: Variants
2366
+ vat_id: VAT-ID
2358
2367
  version: Version
2359
2368
  view_product: View Product On Store
2360
2369
  void: Void
@@ -972,4 +972,96 @@ class SolidusOneFour < ActiveRecord::Migration[5.0]
972
972
  t.datetime "updated_at", precision: 6
973
973
  end
974
974
  end
975
+
976
+ def down
977
+ drop_table "friendly_id_slugs"
978
+ drop_table "spree_addresses"
979
+ drop_table "spree_adjustment_reasons"
980
+ drop_table "spree_adjustments"
981
+ drop_table "spree_assets"
982
+ drop_table "spree_calculators"
983
+ drop_table "spree_cartons"
984
+ drop_table "spree_countries"
985
+ drop_table "spree_credit_cards"
986
+ drop_table "spree_customer_returns"
987
+ drop_table "spree_inventory_units"
988
+ drop_table "spree_line_item_actions"
989
+ drop_table "spree_line_items"
990
+ drop_table "spree_log_entries"
991
+ drop_table "spree_option_type_prototypes"
992
+ drop_table "spree_option_types"
993
+ drop_table "spree_option_values"
994
+ drop_table "spree_option_values_variants"
995
+ drop_table "spree_order_mutexes"
996
+ drop_table "spree_orders"
997
+ drop_table "spree_orders_promotions"
998
+ drop_table "spree_payment_capture_events"
999
+ drop_table "spree_payment_methods"
1000
+ drop_table "spree_payments"
1001
+ drop_table "spree_preferences"
1002
+ drop_table "spree_prices"
1003
+ drop_table "spree_product_option_types"
1004
+ drop_table "spree_product_promotion_rules"
1005
+ drop_table "spree_product_properties"
1006
+ drop_table "spree_products"
1007
+ drop_table "spree_products_taxons"
1008
+ drop_table "spree_promotion_actions"
1009
+ drop_table "spree_promotion_categories"
1010
+ drop_table "spree_promotion_codes"
1011
+ drop_table "spree_promotion_code_batches"
1012
+ drop_table "spree_promotion_rule_taxons"
1013
+ drop_table "spree_promotion_rules"
1014
+ drop_table "spree_promotion_rules_stores"
1015
+ drop_table "spree_promotion_rules_users"
1016
+ drop_table "spree_promotions"
1017
+ drop_table "spree_properties"
1018
+ drop_table "spree_property_prototypes"
1019
+ drop_table "spree_prototype_taxons"
1020
+ drop_table "spree_prototypes"
1021
+ drop_table "spree_refund_reasons"
1022
+ drop_table "spree_refunds"
1023
+ drop_table "spree_reimbursement_credits"
1024
+ drop_table "spree_reimbursement_types"
1025
+ drop_table "spree_reimbursements"
1026
+ drop_table "spree_return_authorizations"
1027
+ drop_table "spree_return_items"
1028
+ drop_table "spree_return_reasons"
1029
+ drop_table "spree_roles"
1030
+ drop_table "spree_roles_users"
1031
+ drop_table "spree_shipments"
1032
+ drop_table "spree_shipping_categories"
1033
+ drop_table "spree_shipping_method_categories"
1034
+ drop_table "spree_shipping_method_stock_locations"
1035
+ drop_table "spree_shipping_method_zones"
1036
+ drop_table "spree_shipping_methods"
1037
+ drop_table "spree_shipping_rate_taxes"
1038
+ drop_table "spree_shipping_rates"
1039
+ drop_table "spree_state_changes"
1040
+ drop_table "spree_states"
1041
+ drop_table "spree_stock_items"
1042
+ drop_table "spree_stock_locations"
1043
+ drop_table "spree_stock_movements"
1044
+ drop_table "spree_store_credit_categories"
1045
+ drop_table "spree_store_credit_events"
1046
+ drop_table "spree_store_credit_types"
1047
+ drop_table "spree_store_credit_update_reasons"
1048
+ drop_table "spree_store_credits"
1049
+ drop_table "spree_store_payment_methods"
1050
+ drop_table "spree_stores"
1051
+ drop_table "spree_tax_rates"
1052
+ drop_table "spree_tax_categories"
1053
+ drop_table "spree_taxonomies"
1054
+ drop_table "spree_taxons"
1055
+ drop_table "spree_unit_cancels"
1056
+ drop_table "spree_user_addresses"
1057
+ drop_table "spree_user_stock_locations"
1058
+ drop_table "spree_variant_property_rule_conditions"
1059
+ drop_table "spree_variant_property_rule_values"
1060
+ drop_table "spree_variant_property_rules"
1061
+ drop_table "spree_variants"
1062
+ drop_table "spree_wallet_payment_sources"
1063
+ drop_table "spree_users"
1064
+ drop_table "spree_zone_members"
1065
+ drop_table "spree_zones"
1066
+ end
975
1067
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AddApplyToAllToVariantPropertyRule < ActiveRecord::Migration[5.1]
4
- def change
4
+ def up
5
5
  add_column :spree_variant_property_rules, :apply_to_all, :boolean, default: false, null: false
6
6
  change_column :spree_variant_property_rules, :apply_to_all, :boolean, default: true
7
7
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddMetadataToSpreeResources < ActiveRecord::Migration[7.2]
3
+ class AddMetadataToSpreeResources < ActiveRecord::Migration[7.0]
4
4
  def change
5
5
  # List of Resources to add metadata columns to
6
6
  %i[
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddReverseChargeStatusToStore < ActiveRecord::Migration[7.0]
4
+ def change
5
+ add_column :spree_stores, :reverse_charge_status, :integer, default: 0, null: false,
6
+ comment: "Enum values: 0 = disabled, 1 = enabled, 2 = not_validated"
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddVatIdEmailAndReverseChargeStatusToAddresses < ActiveRecord::Migration[7.0]
4
+ def change
5
+ add_column :spree_addresses, :vat_id, :string
6
+ add_column :spree_addresses, :email, :string
7
+ add_column :spree_addresses, :reverse_charge_status, :integer, default: 0, null: false,
8
+ comment: "Enum values: 0 = disabled, 1 = enabled, 2 = not_validated"
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class AddEmailToStockLocations < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :spree_stock_locations, :email, :string
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddAddressbookForeignKey < ActiveRecord::Migration[7.0]
4
+ FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]
5
+
6
+ def up
7
+ # Uncomment the following code to remove orphaned records if this migration fails
8
+ #
9
+ # say_with_time "Removing orphaned address book entries (no corresponding address)" do
10
+ # Spree::UserAddress.left_joins(:address).where(spree_addresses: { id: nil }).delete_all
11
+ # end
12
+ add_foreign_key :spree_user_addresses, :spree_addresses, column: :address_id, null: false
13
+ rescue ActiveRecord::StatementInvalid => e
14
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
15
+ say <<~MSG
16
+ ⚠️ Foreign key constraint failed when adding :spree_user_addresses => :spree_addresses.
17
+ To fix this:
18
+ 1. Uncomment the code that removes orphaned records.
19
+ 2. Rerun the migration.
20
+ Offending error: #{e.cause.class} - #{e.cause.message}
21
+ MSG
22
+ end
23
+ raise
24
+ end
25
+
26
+ def down
27
+ remove_foreign_key :spree_user_addresses, :spree_addresses, column: :address_id, null: false
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddFkProductsVariantPropertyRules < ActiveRecord::Migration[7.0]
4
+ FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]
5
+
6
+ def up
7
+ # Uncomment the following code to remove orphaned records if this migration fails
8
+ #
9
+ # say_with_time "Removing orphaned variant property rules (no corresponding product)" do
10
+ # Spree::VariantPropertyRule.left_joins(:product).where(spree_products: { id: nil }).delete_all
11
+ # end
12
+
13
+ add_foreign_key :spree_variant_property_rules, :spree_products, column: :product_id, null: false
14
+ rescue ActiveRecord::StatementInvalid => e
15
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
16
+ say <<~MSG
17
+ ⚠️ Foreign key constraint failed when adding :spree_variant_property_rules => :spree_products.
18
+ To fix this:
19
+ 1. Uncomment the code that removes orphaned records.
20
+ 2. Rerun the migration.
21
+ Offending error: #{e.cause.class} - #{e.cause.message}
22
+ MSG
23
+ end
24
+ raise
25
+ end
26
+
27
+ def down
28
+ remove_foreign_key :spree_variant_property_rules, :spree_products, column: :product_id, null: false
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddFkToProductProperties < ActiveRecord::Migration[7.0]
4
+ FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]
5
+
6
+ def up
7
+ # Uncomment the following code to remove orphaned records if this migration fails
8
+ #
9
+ # say_with_time "Removing orphaned product properties (no corresponding product)" do
10
+ # Spree::ProductProperty.left_joins(:product).where(spree_products: { id: nil }).delete_all
11
+ # end
12
+ begin
13
+ add_foreign_key :spree_product_properties, :spree_products, column: :product_id, null: false
14
+ rescue ActiveRecord::StatementInvalid => e
15
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
16
+ say <<~MSG
17
+ ⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_products.
18
+ To fix this:
19
+ 1. Uncomment the code that removes orphaned records.
20
+ 2. Rerun the migration.
21
+ Offending error: #{e.cause.class} - #{e.cause.message}
22
+ MSG
23
+ end
24
+ raise
25
+ end
26
+
27
+ # Uncomment the following code to remove orphaned records if this migration fails
28
+ #
29
+ # say_with_time "Removing orphaned product properties (no corresponding property)" do
30
+ # Spree::ProductProperty.left_joins(:property).where(spree_properties: { id: nil }).delete_all
31
+ # end
32
+ begin
33
+ add_foreign_key :spree_product_properties, :spree_properties, column: :property_id, null: false
34
+ rescue ActiveRecord::StatementInvalid => e
35
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
36
+ say <<~MSG
37
+ ⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_properties.
38
+ To fix this:
39
+ 1. Uncomment the code that removes orphaned records.
40
+ 2. Rerun the migration.
41
+ Offending error: #{e.cause.class} - #{e.cause.message}
42
+ MSG
43
+ end
44
+ raise
45
+ end
46
+ end
47
+
48
+ def down
49
+ remove_foreign_key :spree_product_properties, :spree_products, column: :product_id, null: false
50
+ remove_foreign_key :spree_product_properties, :spree_properties, column: :property_id, null: false
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddFkToProductOptionTypes < ActiveRecord::Migration[7.0]
4
+ FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]
5
+
6
+ def up
7
+ # Uncomment the following code to remove orphaned records if this migration fails
8
+ #
9
+ # say_with_time "Removing orphaned product option types (no corresponding product)" do
10
+ # Spree::ProductOptionType.left_joins(:product).where(spree_products: { id: nil }).delete_all
11
+ # end
12
+ begin
13
+ add_foreign_key :spree_product_option_types, :spree_products, column: :product_id
14
+ rescue ActiveRecord::StatementInvalid => e
15
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
16
+ say <<~MSG
17
+ ⚠️ Foreign key constraint failed when adding :spree_product_option_types => :spree_products.
18
+ To fix this:
19
+ 1. Uncomment the code that removes orphaned records.
20
+ 2. Rerun the migration.
21
+ Offending error: #{e.cause.class} - #{e.cause.message}
22
+ MSG
23
+ end
24
+ raise
25
+ end
26
+
27
+ # Uncomment the following code to remove orphaned records if this migration fails
28
+ #
29
+ # say_with_time "Removing orphaned product option types (no corresponding option type)" do
30
+ # Spree::ProductOptionType.left_joins(:option_type).where(spree_option_types: { id: nil }).delete_all
31
+ # end
32
+ begin
33
+ add_foreign_key :spree_product_option_types, :spree_option_types, column: :option_type_id
34
+ rescue ActiveRecord::StatementInvalid => e
35
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
36
+ say <<~MSG
37
+ ⚠️ Foreign key constraint failed when adding :spree_product_option_types => :spree_option_types.
38
+ To fix this:
39
+ 1. Uncomment the code that removes orphaned records.
40
+ 2. Rerun the migration.
41
+ Offending error: #{e.cause.class} - #{e.cause.message}
42
+ MSG
43
+ end
44
+ raise
45
+ end
46
+ end
47
+
48
+ def down
49
+ remove_foreign_key :spree_product_option_types, :spree_products, column: :product_id
50
+ remove_foreign_key :spree_product_option_types, :spree_option_types, column: :option_type_id
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddFkToClassifications < ActiveRecord::Migration[7.0]
4
+ FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]
5
+
6
+ def up
7
+ # Uncomment the following code to remove orphaned records if this migration fails
8
+ #
9
+ # say_with_time "Removing orphaned classifications (no corresponding product)" do
10
+ # Spree::Classification.left_joins(:product).where(spree_products: { id: nil }).delete_all
11
+ # end
12
+ begin
13
+ add_foreign_key :spree_products_taxons, :spree_products, column: :product_id
14
+ rescue ActiveRecord::StatementInvalid => e
15
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
16
+ say <<~MSG
17
+ ⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_products.
18
+ To fix this:
19
+ 1. Uncomment the code that removes orphaned records.
20
+ 2. Rerun the migration.
21
+ Offending error: #{e.cause.class} - #{e.cause.message}
22
+ MSG
23
+ end
24
+ raise
25
+ end
26
+
27
+ # Uncomment the following code to remove orphaned records if this migration fails
28
+ #
29
+ # say_with_time "Removing orphaned classifications (no corresponding taxon)" do
30
+ # Spree::Classification.left_joins(:taxon).where(spree_taxons: { id: nil }).delete_all
31
+ # end
32
+ begin
33
+ add_foreign_key :spree_products_taxons, :spree_taxons, column: :taxon_id
34
+ rescue ActiveRecord::StatementInvalid => e
35
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
36
+ say <<~MSG
37
+ ⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_taxons.
38
+ To fix this:
39
+ 1. Uncomment the code that removes orphaned records.
40
+ 2. Rerun the migration.
41
+ Offending error: #{e.cause.class} - #{e.cause.message}
42
+ MSG
43
+ end
44
+ raise
45
+ end
46
+ end
47
+
48
+ def down
49
+ remove_foreign_key :spree_products_taxons, :spree_products, column: :product_id
50
+ remove_foreign_key :spree_products_taxons, :spree_taxons, column: :taxon_id
51
+ end
52
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddShippingCategoryForeignKeys < ActiveRecord::Migration[7.0]
4
+ FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]
5
+
6
+ def change
7
+ # Uncomment the following code to remove orphaned records if the following code fails
8
+ #
9
+ # say_with_time "Removing orphaned products (no corresponding shipping category)" do
10
+ # Spree::Product.left_joins(:shipping_category).where(spree_shipping_category: { id: nil }).delete_all
11
+ # end
12
+ begin
13
+ add_foreign_key :spree_products, :spree_shipping_categories, column: :shipping_category_id, null: false
14
+ rescue ActiveRecord::StatementInvalid => e
15
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
16
+ say <<~MSG
17
+ ⚠️ Foreign key constraint failed when adding :spree_products => :spree_shipping_categories.
18
+ To fix this:
19
+ 1. Uncomment the code that removes orphaned records.
20
+ 2. Rerun the migration.
21
+ Offending error: #{e.cause.class} - #{e.cause.message}
22
+ MSG
23
+ end
24
+ raise
25
+ end
26
+
27
+ # Uncomment the following code to remove orphaned records if the following code fails
28
+ #
29
+ # say_with_time "Removing orphaned shipping method categories (no corresponding shipping category)" do
30
+ # Spree::ShippingMethodCategory.left_joins(:shipping_category).where(spree_shipping_category: { id: nil }).delete_all
31
+ # end
32
+ begin
33
+ add_foreign_key :spree_shipping_method_categories, :spree_shipping_methods, column: :shipping_method_id, null: false
34
+ rescue ActiveRecord::StatementInvalid => e
35
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
36
+ say <<~MSG
37
+ ⚠️ Foreign key constraint failed when adding :spree_shipping_method_categories => :spree_shipping_methods.
38
+ To fix this:
39
+ 1. Uncomment the code that removes orphaned records.
40
+ 2. Rerun the migration.
41
+ Offending error: #{e.cause.class} - #{e.cause.message}
42
+ MSG
43
+ end
44
+ raise
45
+ end
46
+
47
+ # Uncomment the following code to remove orphaned records if the following code fails
48
+ #
49
+ # say_with_time "Removing orphaned shipping method categories (no corresponding shipping method)" do
50
+ # Spree::ShippingMethodCategory.left_joins(:shipping_method).where(spree_shipping_method: { id: nil }).delete_all
51
+ # end
52
+ begin
53
+ add_foreign_key :spree_shipping_method_categories, :spree_shipping_categories, column: :shipping_category_id, null: false
54
+ rescue ActiveRecord::StatementInvalid => e
55
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
56
+ say <<~MSG
57
+ ⚠️ Foreign key constraint failed when adding :spree_shipping_method_categories => :spree_shipping_categories.
58
+ To fix this:
59
+ 1. Uncomment the code that removes orphaned records.
60
+ 2. Rerun the migration.
61
+ Offending error: #{e.cause.class} - #{e.cause.message}
62
+ MSG
63
+ end
64
+ raise
65
+ end
66
+ end
67
+
68
+ def down
69
+ remove_foreign_key :spree_products, :spree_shipping_categories, column: :shipping_category_id, null: false
70
+ remove_foreign_key :spree_shipping_method_categories, :spree_shipping_methods, column: :shipping_method_id, null: false
71
+ remove_foreign_key :spree_shipping_method_categories, :spree_shipping_categories, column: :shipping_category_id, null: false
72
+ end
73
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddForeignKeyToSpreeRoleUsers < ActiveRecord::Migration[7.0]
4
+ FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]
5
+
6
+ def up
7
+ # Uncomment the following code to remove orphaned records if this migration fails
8
+ #
9
+ # say_with_time "Removing orphaned roles/user join records (no corresponding role)" do
10
+ # Spree::RoleUser.left_joins(:role).where(spree_roles: { id: nil }).delete_all
11
+ # end
12
+
13
+ add_foreign_key :spree_roles_users, :spree_roles, column: :role_id, null: false
14
+ rescue ActiveRecord::StatementInvalid => e
15
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
16
+ say <<~MSG
17
+ ⚠️ Foreign key constraint failed when adding :spree_roles_users => :spree_roles.
18
+ To fix this:
19
+ 1. Uncomment the code that removes orphaned records.
20
+ 2. Rerun the migration.
21
+ Offending error: #{e.cause.class} - #{e.cause.message}
22
+ MSG
23
+ end
24
+ raise
25
+ end
26
+
27
+ def down
28
+ remove_foreign_key :spree_roles_users, :spree_roles, column: :role_id, null: false
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ChangeCountriesIsoToUnique < ActiveRecord::Migration[7.0]
4
+ def change
5
+ remove_index :spree_countries, :iso
6
+
7
+ add_index :spree_countries, :iso, unique: true
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddAdjustmentReasonForeignKeys < ActiveRecord::Migration[7.0]
4
+ FOREIGN_KEY_VIOLATION_ERRORS = %w[PG::ForeignKeyViolation Mysql2::Error SQLite3::ConstraintException]
5
+
6
+ def up
7
+ # Uncomment the following code to remove orphaned records if this migration fails
8
+ #
9
+ # say_with_time "Removing invalid adjustment reason IDs from adjustments table" do
10
+ # Spree::Adjustment.where.not(adjustment_reason_id: nil).left_joins(:adjustment_reason).where(spree_adjustment_reasons: { id: nil }).update_all(adjustment_reason_id: nil)
11
+ # end
12
+
13
+ add_foreign_key :spree_adjustments, :spree_adjustment_reasons, column: :adjustment_reason_id, null: true, on_delete: :restrict
14
+ rescue ActiveRecord::StatementInvalid => e
15
+ if e.cause.class.name.in?(FOREIGN_KEY_VIOLATION_ERRORS)
16
+ say <<~MSG
17
+ ⚠️ Foreign key constraint failed when adding :spree_adjustments => :spree_adjustment_reasons.
18
+ To fix this:
19
+ 1. Uncomment the code that removes invalid adjustment reason IDs from the spree_adjustments table.
20
+ 2. Rerun the migration.
21
+ Offending error: #{e.cause.class} - #{e.cause.message}
22
+ MSG
23
+ end
24
+ raise
25
+ end
26
+
27
+ def down
28
+ remove_foreign_key :spree_adjustments, :spree_adjustment_reasons, column: :adjustment_reason_id, null: true, on_delete: :restrict
29
+ end
30
+ end