Jeff Hastings
09/14/2022, 3:00 PMUNIQUE
in postgres, it creates a unique constraint. With Prisma and @@unique
, it just creates a unique index.
For example
model AnotherUser {
id Int @id @default(autoincrement())
firstName String?
lastName String?
@@unique([firstName, lastName])
}
Generates the following migration
-- CreateTable
CREATE TABLE "AnotherUser" (
"id" SERIAL NOT NULL,
"firstName" TEXT,
"lastName" TEXT,
CONSTRAINT "AnotherUser_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "AnotherUser_firstName_lastName_key" ON "AnotherUser"("firstName", "lastName");
And the table description lists it as simply UNIQUE
"AnotherUser_firstName_lastName_key" UNIQUE, btree ("firstName", "lastName")
And I don’t see a constraint in pg_constraint
.
BUT if I create the same table with UNIQUE
CREATE TABLE "AnotherUser" (
"id" SERIAL NOT NULL,
"firstName" TEXT,
"lastName" TEXT,
CONSTRAINT "AnotherUser_pkey" PRIMARY KEY ("id"),
UNIQUE("firstName", "lastName")
);
The table description lists the unique constraint
"AnotherUser_firstName_lastName_key" UNIQUE CONSTRAINT, btree ("firstName", "lastName")
And I can see the constraint in pg_constraint
Does anyone know why Prisma Migrate is only creating unique indexes and not unique constraints (which are backed by a unique index)?Nurul
09/20/2022, 4:16 PMJeff Hastings
09/20/2022, 4:28 PM$ npx prisma --version
Environment variables loaded from .env
prisma : 4.3.1
@prisma/client : 4.0.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules/@prisma/engines/prisma-fmt-darwin)
Format Wasm : @prisma/prisma-fmt-wasm 4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b
Default Engines Hash : c875e43600dfe042452e0b868f7a48b817b9640b
Studio : 0.473.0
Nurul
09/23/2022, 11:57 AM