Skip to content

Conversation

@mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Jul 9, 2025

Summary

This adds foreign key constraints, inverse_of and dependent options 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:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Jul 9, 2025
@mamhoff mamhoff force-pushed the country-dependent branch from 1465d62 to 449838a Compare July 9, 2025 09:06
@github-actions github-actions bot added the changelog:solidus_backend Changes to the solidus_backend gem label Jul 9, 2025
@mamhoff mamhoff changed the title Country: Add dependent/inverse_of options Country and state: Restrict deletion if addresses present Jul 9, 2025
@mamhoff mamhoff force-pushed the country-dependent branch 6 times, most recently from 10a9d0a to 601f6c8 Compare July 9, 2025 11:50
@mamhoff mamhoff force-pushed the country-dependent branch 2 times, most recently from d71d3b1 to 60b8a8f Compare July 9, 2025 12:26
@github-actions github-actions bot added the changelog:solidus_api Changes to the solidus_api gem label Jul 9, 2025
@codecov
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.99%. Comparing base (72b8c40) to head (60b8a8f).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mamhoff mamhoff marked this pull request as ready for review July 9, 2025 13:01
@mamhoff mamhoff requested a review from a team as a code owner July 9, 2025 13:01
@tvdeyen tvdeyen added this to the 4.6 milestone Jul 9, 2025
@tvdeyen tvdeyen removed this from Solidus Admin Jul 9, 2025
@tvdeyen tvdeyen moved this to In Progress in Solidus Public Roadmap Jul 9, 2025
@tvdeyen
Copy link
Member

tvdeyen commented Jul 23, 2025

@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.
@mamhoff mamhoff force-pushed the country-dependent branch from 60b8a8f to 8caa042 Compare July 26, 2025 15:14
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.
mamhoff added 2 commits July 26, 2025 09:17
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.
@mamhoff mamhoff force-pushed the country-dependent branch from 8caa042 to 737f092 Compare July 26, 2025 15:17
Copy link
Contributor Author

@mamhoff mamhoff left a 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

@tvdeyen tvdeyen merged commit 907bf8a into solidusio:main Aug 5, 2025
37 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Solidus Public Roadmap Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_admin changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem

Projects

Development

Successfully merging this pull request may close these issues.

5 participants