Skip to content

Commit 46edaff

Browse files
committed
feat: add unique index on chat to allow update chat label
1 parent 93d6084 commit 46edaff

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[instanceId,remoteJid]` on the table `Chat` will be added. If there are existing duplicate values, this will fail.
5+
6+
*/
7+
-- CreateIndex
8+
DO $$
9+
BEGIN
10+
IF NOT EXISTS (
11+
SELECT 1 FROM pg_indexes
12+
WHERE indexname = 'Chat_instanceId_remoteJid_key'
13+
) THEN
14+
CREATE UNIQUE INDEX "Chat_instanceId_remoteJid_key" ON "Chat"("instanceId", "remoteJid");
15+
END IF;
16+
END
17+
$$;

prisma/postgresql-schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ model Chat {
125125
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
126126
instanceId String
127127
unreadMessages Int @default(0)
128+
@@unique([instanceId, remoteJid])
128129
@@index([instanceId])
129130
@@index([remoteJid])
130131
}

0 commit comments

Comments
 (0)