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

db.constraint assumes a unique index implies a matching constraint #138

Open
scottcollabai opened this issue Feb 3, 2023 · 1 comment
Open

Comments

@scottcollabai
Copy link

scottcollabai commented Feb 3, 2023

Hi there -- huge fan of Zapatos!

Issue: db.constraint takes in UniqueIndexForTable as its parameter. However, if one were to enforce column value uniqueness using CREATE UNIQUE INDEX directly (instead of ALTER TABLE ... ADD CONSTRAINT), you wind up with a 'valid' value for db.constraint that results in a runtime error from Postgres if you actually try to use it.

Per the PG docs I don't think it's preferred to use CREATE UNIQUE INDEX in this way, but in our case, we use Prisma Migrate to generate our schema migration scripts. Prisma Migrate so happens to only generate a CREATE UNIQUE INDEX statement if you mark a column as @unique in the Prisma schema, so it's actually quite easy for us to hit this issue in practice. That's likely an issue on their end too...

@scottcollabai scottcollabai changed the title Schema generation assumes a unique index implies a matching constraint db.constraint assumes a unique index implies a matching constraint Feb 3, 2023
@jawj
Copy link
Owner

jawj commented Feb 15, 2023

So it sounds like Zapatos wrongly identifies some indexes as valid for use in an upsert that aren't actually? I haven't got a lot of time to work on this right now. Do you happen to know how we'd need to change the relevant query that's run at generation time?

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

No branches or pull requests

2 participants