You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Schemas with the same table name can not be synced with constraints #15639
pending-approvalBug reports that have not been verified yet, or feature requests that have not been accepted yetstaletype: bugDEPRECATED: replace with the "bug" issue type
If I have two different schemas in my PostgreSQL database and they both share a table with the same name. The sequelize.sync({ force: true }) command will try to delete the constraints from the other table. This always leads to an error that states: parent: error: relation "schema_name.table_name" does not exist.
Constraints should only be dropped, If the current schema has them associated. Besides the name of the constraints, the namespace should also be checked.
What is actually happening?
The sql output states to delete the constraints:
'ALTER TABLE "schema_name"."table_name" DROP CONSTRAINT "table_name_number_id_fkey"'.
The constraint table_name_number_id_fkey does not exist in my current schema but in the other schema.
No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
You're defining two different models with the same name, User. The second model overwrites the first one so the model for schema_a doesn't exist in sequelize.models anymore, and does not get synched
This is something I plan on banning eventually, all model names must be unique
Hello @ephys thanks for your answer.
Unfortunately the sscce repo does not allow me to picture our case precisely. Here is more information about what is happening:
We are working with a microservice architecture of multiple node.js backends. Each backend creates tables and saves data dedicated to their own schema in a single database (multi-tenant service postgreSQL database).
If in two microservices there is a model with the same name, there is no direct way of telling if it is duplicated, because sequelize.sync({ force: true }) is called for each service respectively. Besides that, this is not our issue here.
The real issue is, that constraints from one schema are deleted by the sequelize instance in another service with another schema, if the model name is the same. This should not be possible, because constraints are created for a specific schema.
The solution for this case should be that only constraints from the current schema should be dropped, not all constraints that follow a certain model name, found my sequelize. Otherwise we would drop constraints from other apps running in our database which is crucial.
This bug report has not been verified by maintainers yet, and has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, consider commenting with more information to help us verify it.
pending-approvalBug reports that have not been verified yet, or feature requests that have not been accepted yetstaletype: bugDEPRECATED: replace with the "bug" issue type
Activity
ephys commentedon Feb 3, 2023
You're defining two different models with the same name,
User. The second model overwrites the first one so the model for schema_a doesn't exist insequelize.modelsanymore, and does not get synchedThis is something I plan on banning eventually, all model names must be unique
dspintelegence commentedon Feb 8, 2023
Hello @ephys thanks for your answer.
Unfortunately the sscce repo does not allow me to picture our case precisely. Here is more information about what is happening:
We are working with a microservice architecture of multiple node.js backends. Each backend creates tables and saves data dedicated to their own schema in a single database (multi-tenant service postgreSQL database).
If in two microservices there is a model with the same name, there is no direct way of telling if it is duplicated, because
sequelize.sync({ force: true })is called for each service respectively. Besides that, this is not our issue here.The real issue is, that constraints from one schema are deleted by the sequelize instance in another service with another schema, if the model name is the same. This should not be possible, because constraints are created for a specific schema.
The solution for this case should be that only constraints from the current schema should be dropped, not all constraints that follow a certain model name, found my sequelize. Otherwise we would drop constraints from other apps running in our database which is crucial.
ephys commentedon Mar 2, 2023
forcedrops the table before creating it, if multiple instances are touching the same table, they will fully reset themgithub-actions commentedon Mar 17, 2023
This bug report has not been verified by maintainers yet, and has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, consider commenting with more information to help us verify it.