-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
fix: filter also on schema name when retrieving foreign keys #16770
base: v6
Are you sure you want to change the base?
Conversation
d8c1be1
to
ba945ef
Compare
PR #16785 on v7 shows that this issue is already fixed on v7, but I'm interested in a fix in v6 as well. |
@WikiRik, the PR on v7 has been merged. Is it possible to merge this one as well? It fixes an issue with foreign keys retrieval. |
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.
Looks good, I have one comment regarding mysql/mariadb though. There are unit tests that we could add with different schemas, but we have those in v7 and we hope to release that soon so I think it's fine if we don't add them here
@@ -40,5 +40,51 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => { | |||
expect(refs[0]).deep.include.all(expectedObject); | |||
|
|||
}); | |||
|
|||
describe('with schemas', () => { | |||
// MariaDB does not really support schemas (they are synonyms of databases) |
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.
Is this behaviour different between mariadb and mysql?
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.
For MySQL, Support.sequelize.dialect.supports.schemas
is false
, but for MariaDB it's true (even though it does not really support schemas).
You can see it there:
This would be a breaking change though, as the behavior would change. It would be better to do this in v7 |
I added tests in v7 to check that it's already working as expected (and it is). I agree that the behavior will change, but the behavior is buggy. For instance in PG, there is a condition to retrieve info only about the table in the right schema, but the condition has not been added to the JOIN conditions. Meaning that it'll retrieve foreign keys of tables with the same name from other schemas. |
Pull Request Checklist
Description Of Change
When retrieving the list of foreign keys of a table on Postgresql, relationships are not filtered by schema. It means that if a different schema contains the same table,
getForeignKeyReferencesForTable
will also return relationships of this second table.This PR fixes this issue by filtering also by database name and schema name to be sure that only FKs from the requested table are retrieved.