-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add dependent/inverse_of options to product-related models #6271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tvdeyen
merged 6 commits into
solidusio:main
from
mamhoff:foreign-key-inverse-of-product-taxons
Jun 20, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4eb11e
Product: Add dependent: options
mamhoff 7abddf9
Taxonomy: Add dependent: false options
mamhoff b838948
Add foreign key constraint to variant property rules
mamhoff 48c183e
Spree::ProductProperties: Add foreign key constraints
mamhoff 4ebac06
ProductOptionType: Add foreign key constraints
mamhoff 04493b1
Classifications: Add foreign keys
mamhoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/db/migrate/20250604072105_add_fk_products_variant_property_rules.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddFkProductsVariantPropertyRules < ActiveRecord::Migration[7.0] | ||
| def up | ||
| # Uncomment the following code to remove orphaned records if this migration fails | ||
| # | ||
| # say_with_time "Removing orphaned variant property rules (no corresponding product)" do | ||
| # Spree::VariantPropertyRule.left_joins(:product).where(spree_products: { id: nil }).delete_all | ||
| # end | ||
|
|
||
| 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 | ||
| ⚠️ Foreign key constraint failed when adding :spree_variant_property_rules => :spree_products. | ||
| To fix this: | ||
| 1. Uncomment the code that removes orphaned records. | ||
| 2. Rerun the migration. | ||
| Offending error: #{e.cause.class} - #{e.cause.message} | ||
| MSG | ||
| end | ||
| raise | ||
| end | ||
|
|
||
| def down | ||
| remove_foreign_key :spree_variant_property_rules, :spree_products, column: :product_id, null: false | ||
| end | ||
| end | ||
50 changes: 50 additions & 0 deletions
50
core/db/migrate/20250604072555_add_fk_to_product_properties.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddFkToProductProperties < ActiveRecord::Migration[7.0] | ||
| def up | ||
| # Uncomment the following code to remove orphaned records if this migration fails | ||
| # | ||
| # say_with_time "Removing orphaned product properties (no corresponding product)" do | ||
| # Spree::ProductProperty.left_joins(:product).where(spree_products: { id: nil }).delete_all | ||
| # end | ||
| 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 | ||
| ⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_products. | ||
| To fix this: | ||
| 1. Uncomment the code that removes orphaned records. | ||
| 2. Rerun the migration. | ||
| Offending error: #{e.cause.class} - #{e.cause.message} | ||
| MSG | ||
| end | ||
| raise | ||
| end | ||
|
|
||
| # Uncomment the following code to remove orphaned records if this migration fails | ||
| # | ||
| # say_with_time "Removing orphaned product properties (no corresponding property)" do | ||
| # Spree::ProductProperty.left_joins(:property).where(spree_properties: { id: nil }).delete_all | ||
| # end | ||
| 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 | ||
| ⚠️ Foreign key constraint failed when adding :spree_product_properties => :spree_properties. | ||
| To fix this: | ||
| 1. Uncomment the code that removes orphaned records. | ||
| 2. Rerun the migration. | ||
| Offending error: #{e.cause.class} - #{e.cause.message} | ||
| MSG | ||
| end | ||
| raise | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| remove_foreign_key :spree_product_properties, :spree_products, column: :product_id, null: false | ||
| remove_foreign_key :spree_product_properties, :spree_properties, column: :property_id, null: false | ||
| end | ||
| end |
50 changes: 50 additions & 0 deletions
50
core/db/migrate/20250604072948_add_fk_to_product_option_types.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddFkToProductOptionTypes < ActiveRecord::Migration[7.0] | ||
| def up | ||
| # Uncomment the following code to remove orphaned records if this migration fails | ||
| # | ||
| # say_with_time "Removing orphaned product option types (no corresponding product)" do | ||
| # Spree::ProductOptionType.left_joins(:product).where(spree_products: { id: nil }).delete_all | ||
| # end | ||
| 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 | ||
| ⚠️ Foreign key constraint failed when adding :spree_product_option_types => :spree_products. | ||
| To fix this: | ||
| 1. Uncomment the code that removes orphaned records. | ||
| 2. Rerun the migration. | ||
| Offending error: #{e.cause.class} - #{e.cause.message} | ||
| MSG | ||
| end | ||
| raise | ||
| end | ||
|
|
||
| # Uncomment the following code to remove orphaned records if this migration fails | ||
| # | ||
| # say_with_time "Removing orphaned product option types (no corresponding option type)" do | ||
| # Spree::ProductOptionType.left_joins(:option_type).where(spree_option_types: { id: nil }).delete_all | ||
| # end | ||
| 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 | ||
| ⚠️ Foreign key constraint failed when adding :spree_product_option_types => :spree_option_types. | ||
| To fix this: | ||
| 1. Uncomment the code that removes orphaned records. | ||
| 2. Rerun the migration. | ||
| Offending error: #{e.cause.class} - #{e.cause.message} | ||
| MSG | ||
| end | ||
| raise | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| remove_foreign_key :spree_product_option_types, :spree_products, column: :product_id | ||
| remove_foreign_key :spree_product_option_types, :spree_option_types, column: :option_type_id | ||
| end | ||
| end |
50 changes: 50 additions & 0 deletions
50
core/db/migrate/20250604073219_add_fk_to_classifications.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddFkToClassifications < ActiveRecord::Migration[7.0] | ||
| def up | ||
| # Uncomment the following code to remove orphaned records if this migration fails | ||
| # | ||
| # say_with_time "Removing orphaned classifications (no corresponding product)" do | ||
| # Spree::Classification.left_joins(:product).where(spree_products: { id: nil }).delete_all | ||
| # end | ||
| 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 | ||
| ⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_products. | ||
| To fix this: | ||
| 1. Uncomment the code that removes orphaned records. | ||
| 2. Rerun the migration. | ||
| Offending error: #{e.cause.class} - #{e.cause.message} | ||
| MSG | ||
| end | ||
| raise | ||
| end | ||
|
|
||
| # Uncomment the following code to remove orphaned records if this migration fails | ||
| # | ||
| # say_with_time "Removing orphaned classifications (no corresponding taxon)" do | ||
| # Spree::Classification.left_joins(:taxon).where(spree_taxons: { id: nil }).delete_all | ||
| # end | ||
| 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 | ||
| ⚠️ Foreign key constraint failed when adding :spree_products_taxons => :spree_taxons. | ||
| To fix this: | ||
| 1. Uncomment the code that removes orphaned records. | ||
| 2. Rerun the migration. | ||
| Offending error: #{e.cause.class} - #{e.cause.message} | ||
| MSG | ||
| end | ||
| raise | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| remove_foreign_key :spree_products_taxons, :spree_products, column: :product_id | ||
| remove_foreign_key :spree_products_taxons, :spree_taxons, column: :taxon_id | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.