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

Postgres migrations should not trigger if the unique key is too long #1515

Open
parsonsmatt opened this issue Aug 29, 2023 · 2 comments
Open

Comments

@parsonsmatt
Copy link
Collaborator

A table with a long uniqueness key will trigger a migration, but Postgres will silently truncate it to the original length. persistent-postgresql's migrations should truncate the name of a constraint before checking if it needs to be renamed.

@MaxGabriel
Copy link
Member

MaxGabriel commented Aug 29, 2023

With foreign keys, it was possible to match the names Postgres auto-generates #996

IIRC for uniqueness constraints, Persistent's DB generated name is based off the Haskell name (eg UniqueOrganizationPaymentAuthorizationControlsOrganizationId), not what database table/column names are (eg organization_id.

I think because of this, Persistent could just do a simple truncation to the max length, rather than trying to match the auto-generated names like we do for FKs

(Not 100% on all of this, working from memory)

@Vlix
Copy link
Contributor

Vlix commented Sep 1, 2023

I recently checked this to explain to a new employee, and yes, the Haskell name you define will be turned into lower-snake-case and used as the uniqueness constraint name. So if there's a max length, the TH could just throw an exception and/or it could be auto-truncated (but I'd imagine that might lead to conflicts with the Haskell names being different, but the truncated ones overlapping in Postgres)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants