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
Prisma tries to re-create indexes in migration if they were previously created with "WHERE" #14651
Comments
WHERE
Still actual for v4.4.0 |
Still actual for v4.6.1 |
Still actual for v4.7.0 |
It will unfortunately keep doing that until we either implement support for conditional indexes (#3076) or we change our behavior here explicitly. We are aware and will evaluate which options we can implement sooner. How did the |
I don't fully understand your question. All schema was written and changing manually by hands. Having two partial indexes is required by bussines logic. I tested it: I apply first migration with partial indexes and canceled second one. Then generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model ShortLink {
id Int @id @default(autoincrement())
slug String?
domainId String?
}
/*
Warnings:
- A unique constraint covering the columns `[slug]` on the table `ShortLink` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[slug,domainId]` on the table `ShortLink` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "ShortLink_slug_key" ON "ShortLink"("slug");
-- CreateIndex
CREATE UNIQUE INDEX "ShortLink_slug_domainId_key" ON "ShortLink"("slug", "domainId"); And it failt with Database error
You mean after the first /*
Warnings:
- A unique constraint covering the columns `[slug]` on the table `ShortLink` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "ShortLink_slug_key" ON "ShortLink"("slug"); |
Ok. So you solution would be to remove both |
May be. But, as I said, that data must be unique as required by the business logic. In addition, it can lead to typescript errors like: db.findUnique({
where: {
slug: ' ... ' // <- may throw error because in scheme `slug` isn't actually unique
}
}) |
With #3076 not implemented, so Prisma not fully supporting conditional indexes, you will have to choose between either Migrate always trying to create a unique index that already exists as a conditional unique index - and hence modify the migration file - or find a workaround for the type problems. Most probably modifying the migration file is easier and more effective. |
(Feature request issue has changed to #13417) |
Bug description
Prisma tries to re-create indexes if they were previously created with "WHERE"
How to reproduce
https://github.com/cawa-93/issue-prisma-migration Demo repository in which the first 3 steps were applied.
npx prisma migrate dev --create-only --name domains
.npx prisma migrate dev
to apply this migration. You should note that this migration has been applied. However, prisma does not understand that the indexesShortLink_slug_key
andShortLink_slug_domainId_key
have been created, considers that the current database and the schema are not synchronized and tries to create these indexes again.Expected behavior
Just normal migration
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: