prisma icon indicating copy to clipboard operation
prisma copied to clipboard

SQL Server - Constraint is tried to be dropped when remoing composite unique fields declaration

Open hbendev opened this issue 3 years ago • 0 comments

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

  1. Remove a multi-column unique constraint
  2. 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

hbendev avatar Sep 16 '22 20:09 hbendev