sea-schema
sea-schema copied to clipboard
`referential_key_table_name` empty for some schemas (panic on Option::unwrap on None during migration) since sea-schema 0.14.2
Hi everyone, thanks so much for your great work on the entire SeaQL project ❤️
Description
This week we found an issue where sea-orm-cli generate entity
fails with a panic in sea-schema's table_constraints.rs
here when it tries to unwrap the Option result.referential_key_table_name
that is None
in our case.
This seems to be the same error behavior as described in https://github.com/SeaQL/sea-orm/discussions/2131.
Steps to Reproduce
- Have a situation where one table T1 has a foreign key (FK) that references a column C in another table T2, where there is a unique index on C but not a unique key (which postgres lets you do, see this SO answer)
- Run
sea-orm-cli generate entity
Expected Behavior
The entities should be generated according to the schema.
If there is a problem with the schema, an informative error message should be printed.
Actual Behavior
The tool panics without any useful error message.
Reproduces How Often
Always (with our schema)
Versions
We are using postgres 14.5.
This issue occurs for us when sea-orm-cli is using [email protected]
and does not occur when sea-orm-cli is using [email protected]
.
We first noticed this after one of our team members recently installed the latest version of sea-orm-cli (0.12.15) where this issue occurred, while on another person's machine it was still working with an older installation of [email protected]
. When that person upgraded to latest, they also experienced the error.
We also noticed that when you install an older version of sea-orm-cli with only the version selector (e.g. cargo install [email protected]
), Cargo will still use the newest dependencies that match the tool's dependencies spec and will not use the versions that it was published with.
Since sea-orm-cli used the dependency sea-schema = { version = "0.14.0" }
(see here) up to 0.12.11, the newer patch version 0.14.2 of sea-schema still matches that version specifier and gets used.
To install an older sea-orm-cli with an older sea-schema for comparative testing, you can use the --locked
switch to make Cargo use the versions used at time of publishing, e.g. cargo install --locked [email protected]
.
Additional Information
Here's a shell script that creates a postgres docker container, creates two tables with the unique/FK combination that causes the problem, and then runs sea-orm-cli generate entity
on it to trigger the issue.
You need to have docker
and [email protected]
on the PATH
for this to work.
https://gist.github.com/Patrick-Lehner-Woven-by-Toyota/811668880cf78a1bc78c679993ce137d