Skip to content

Foreign keys whose referenced table change are not updated by migrations #5119

@csuich2

Description

@csuich2

Issue type:

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

Database system/driver:

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

TypeORM version:

[x] latest
[x] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

It appears that migrations do not generate up and down statements to modify a foreign key when the referenced table changes. This maybe be a dup of #3509, but I have a reproduction repo and believe I found the root cause and potential solution.

After digging for a solution, I found that DefaultNamingStrategy does not incorporate the referenced table name when generating a foreign key name, despite it being a parameter to the method.

Off the top of my head, I see two solutions so far:

  1. Update the naming strategy to incorporate the referenced table name. However, this would cause a lot of noise for all users since all foreign keys would be renamed.
  2. Update RdbmsSchemaBuilder.dropOldForeignKeys() and RdbmsSchemaBuilder.createForeignKeys() to check for the change in referenced table name and generate a new FK with the same name.

Any other thoughts on how to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions