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

Default constraintIdentifier algorithm is corrupted, but it’s breaking to fix #508

Open
stevapple opened this issue May 26, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@stevapple
Copy link
Sponsor Contributor

Describe the bug

The current implementation of constraintIdentifier for foreign key prefixed all local and foreign fields with the local table name, but the output is not unique in fact.

To Reproduce

db.schema("a")
    .field("id", .uuid, .identifier(auto: false))
    .foreignKey("id", references: "b", "id")
    .foreignKey("id", references: "c", "id")
    .create()

Both constraint has the identifier fk:a.id+a.id, so the creation would fail.

Expected behavior

For the example above, the identifiers should be:

  • fk:a.id+b.id
  • fk:a.id+c.id

Additional context

Fixing the implementation is easy, but this affects all existing foreign keys without explicit naming, and users cannot delete them by deleteConstraint(_ constraint: DatabaseSchema.ConstraintDelete), so it is breaking and should be noticed in the upgrading guide.

@stevapple stevapple added the bug Something isn't working label May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant