-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Country and state: Restrict deletion if addresses present #6305
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
Conversation
1465d62 to
449838a
Compare
10a9d0a to
601f6c8
Compare
d71d3b1 to
60b8a8f
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6305 +/- ##
=======================================
Coverage 88.99% 88.99%
=======================================
Files 863 863
Lines 18425 18427 +2
=======================================
+ Hits 16398 16400 +2
Misses 2027 2027 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@mamhoff we need some manual conflict resolving here. |
This also removes a bogus spec that tested admin behavior when dealing with the situation where a country was removed that had been used for an address. This commit prevents that entire situation. The original issue that was solved with the PR that introduced the spec was spree/spree#3571 - allowing admins to add/remove countries, but even here the original developers did not deal with dependent records. For the use case described there - i would like to change the countries my store services - I think using zones is a better solution that deleting the country.
60b8a8f to
8caa042
Compare
We're using `spree_countries.iso` as a primary key between prices and countries. In order to add a foreign key constraint, primary keys have to be unique. This adds the necessary uniqueness constraint. A few tests had to be amended to not create the same country many times.
This adds database-level foreign key constraints to tables that reference the countries table. If trying to delete a country, and there are addresses referencing that country, we want to restrict that. Addresses are immutable and must stay valid. If there are prices referencing the country, the same applies, we want to restrict. If the only thing holding us back from deleting a country is states, we can delete the state records as well.
For the database, a state is optional on an address. What this commit ensures is that any state ID entered into the `state_id` column on `spree_addresses` is actually present in the `spree_states` table.
8caa042 to
737f092
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased on current main. This already has the fixes from #6308
Summary
This adds foreign key constraints,
inverse_ofanddependentoptions to relations between addresses, countries, and states. We want these records to be rock-solid.Extracted from #6240
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: