Missing foreign keys #4006
Replies: 2 comments
-
I don't think discussion was ever closed on this topic. #2253 is still open because, as far as I know, we'd still like to improve the completeness of our foreign keys. Probably worth continuing the discussion over on that issue since you have thoughts on how we might be able to do it. |
Beta Was this translation helpful? Give feedback.
-
Yes, we'd like to add missing FKs but this will break a lot of old stores that have invalid data in production.
I also see this as a path forward, to expand what you propsed:
This could solve the issue but then we'd have unpredictable database structures to deal with, which IMHO is worst in terms of maintainability for Solidus. |
Beta Was this translation helpful? Give feedback.
-
I've recently found that at my very big surprise, there were a lot of foreign keys missing in my schema.
For exemple, on a brand new store, inventory units don't have any FK, even to line items.
There was a try to fix that through #2036 and it was briefly discussed in #2253 but it seems that no solution has been found.
I'm posting here as the issue already exists and as I think this topics needs a discussion more than an issue at the moment.
One way I think about "fixing" this, is by having a migration which is run only on setups (TBH, I don't know if it's even possible but it would set new store on a great start).
Another way would be to try to create each foreign key in a transaction and fallback to NOOP if corrupt data exists.
Yet another way could be to provide a migration with "invalid" FK to Postgres users as this DB engine supports them with the NOT VALID option. We could create a constraint that will not check old values but ensure new inserts or updates are correct so in the long run, old shops will be in a far better shape with their data than they are now.
Is the core team willing to reopen discussion on this topic ?
Do you have other options in mind ?
Beta Was this translation helpful? Give feedback.
All reactions