prisma
prisma copied to clipboard
SQL Server - Constraint is tried to be dropped when remoing composite unique fields declaration
Bug description
When a multi-column unique constraint declaration is removed prisma migrate creates an incorrect migration.
Unique constraint is handled by creating an index in SQL Server:
-- CreateIndex
CREATE UNIQUE INDEX [Answer_questionId_companyId_key] ON [dbo].[Answer]([questionId], [companyId]);
However, after removing it from the schema file, Prisma tries to remove a constraint on the db level.
-- DropIndex
ALTER TABLE [dbo].[Answer] DROP CONSTRAINT [Answer_questionId_companyId_key];
How to reproduce
- Remove a multi-column unique constraint
- Run
npx prisma migrate dev --create-only
Expected behavior
-- DropIndex
DROP Index [Answer_questionId_companyId_key] ON [dbo].[Answer];
Prisma information
model Answer {
...
// ====== References ======
question Question @relation(fields: [questionId], references: [id], onDelete: NoAction, onUpdate: NoAction)
company Company @relation(fields: [companyId], references: [id], onDelete: NoAction, onUpdate: NoAction)
...
// ====== Reference IDs ======
questionId String
companyId String
...
// @@unique([questionId, companyId])
}
Environment & setup
- OS: Ubuntu 20.04
- Database: SQL Server
- Node.js version: v16.16.0
Prisma Version
3.11.0