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

Prefer unique constraints over indexes on SQL Server #3018

Merged
merged 2 commits into from
Jun 30, 2022

Conversation

pimeys
Copy link
Contributor

@pimeys pimeys commented Jun 29, 2022

Unique constraint and index do not differ in SQL Server today. The problem is if we create an index and try to drop a constraint, the drop fails.

Currently if the unique is added when the table is created, we add constraint. If the table is altered with a unique constraint we create an index instead. Dropping this does not work.

The PR makes altering the table with an @unique to use constraints instead of an index.

Closes: prisma/prisma#14051

@pimeys pimeys requested a review from a team as a code owner June 29, 2022 18:35
Unique constraint and index do not differ in SQL Server today. The
problem is if we create an index and try to drop a constraint, the
drop fails.

Currently if the unique is added when the table is created, we add
constraint. If the table is altered with a unique constraint we create
an index instead. Dropping this does not work.

The PR makes altering the table with an `@unique` to use constraints
instead of an index.

Closes: prisma/prisma#14051
@pimeys pimeys force-pushed the migration-engine/unique-drop-test branch from d42e5a4 to c68ecc8 Compare June 29, 2022 18:43
@pimeys pimeys added this to the 4.1.0 milestone Jun 29, 2022
We always create constraints, but if the project has used an index, we
drop an index instead of a constraint if wanting to remove it.
Copy link
Contributor

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat 👍

@pimeys pimeys merged commit f3b52fa into main Jun 30, 2022
@pimeys pimeys deleted the migration-engine/unique-drop-test branch June 30, 2022 10:00
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

Successfully merging this pull request may close these issues.

Incorrect migration creates on sql server when index deleted
2 participants