Skip to content
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

Wrong foreign key information loaded from schema #6168

Closed
weckx opened this issue May 31, 2020 · 0 comments · Fixed by #6828 or GulajavaMinistudio/typeorm#344
Closed

Wrong foreign key information loaded from schema #6168

weckx opened this issue May 31, 2020 · 0 comments · Fixed by #6828 or GulajavaMinistudio/typeorm#344

Comments

@weckx
Copy link

weckx commented May 31, 2020

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[x] 0.2.5

Steps to reproduce or a small repository showing the problem:

When using MySQL/MariaDB if you have an entity with a foreign key and it is created in two different schemas (i.e. a development schema and a staging schema) on the same server, the information loaded from the schema is non-deterministic, as it can come from either schema, due to a missing clause in the query used to load the data from MySQL's information schema.

A simple way to test this is:

  1. Create an entity with a ManyToOne relation to another entity
  2. Generate the migration and synchronize to the database
  3. Change the schema for the entity
  4. Change the ManyToOne relation onUpdate and/or onDelete values
  5. Generate the migration for the new schema
  6. Apply the migration
  7. Generate a new migration. Due to the wrong information loaded the onUpdate or onDelete values might come from the wrong schema and generate an unnecessary foreign key recreation
imnotjames pushed a commit that referenced this issue Oct 4, 2020
Fixes an edge case where the wrong foreign key 
would be loaded when multiple databases exist 
with foreign keys that have the same name.

Fixes #6168
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
Fixes an edge case where the wrong foreign key 
would be loaded when multiple databases exist 
with foreign keys that have the same name.

Fixes typeorm#6168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment