fluent-kit
fluent-kit copied to clipboard
Default `constraintIdentifier` algorithm is corrupted, but it’s breaking to fix
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.