Skip to content

Commit 37a9e31

Browse files
committed
Refactor database migrations and schema for Chat and Setting tables
- Removed the unique constraint on `remoteJid` and `instanceId` in the `Chat` model to prevent potential migration failures due to existing duplicates. - Deleted the old migration file for adding `wavoipToken` to the `Setting` table and created a new migration that includes a check for the column's existence before adding it, ensuring smoother migration processes. - Updated migration logic to clear previous migrations related to `wavoip_token` to maintain a clean migration history.
1 parent f340f77 commit 37a9e31

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

prisma/postgresql-migrations/20250116001412_add_wavoip_token_to_settings_table/migration.sql

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[remoteJid,instanceId]` on the table `Chat` will be added. If there are existing duplicate values, this will fail.
5+
6+
*/
7+
8+
-- Clear migrations
9+
DELETE FROM "_prisma_migrations" WHERE "migration_name" LIKE '%_add_wavoip_token_to_settings_table';
10+
-- AlterTable
11+
DO $$
12+
BEGIN
13+
IF NOT EXISTS (
14+
SELECT 1
15+
FROM information_schema.columns
16+
WHERE table_name = 'Setting'
17+
AND column_name = 'wavoipToken'
18+
) THEN
19+
ALTER TABLE "Setting" ADD COLUMN "wavoipToken" VARCHAR(100);
20+
END IF;
21+
END $$;

prisma/postgresql-schema.prisma

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ model Chat {
127127
unreadMessages Int @default(0)
128128
@@index([instanceId])
129129
@@index([remoteJid])
130-
@@unique([remoteJid, instanceId])
131130
}
132131

133132
model Contact {

0 commit comments

Comments
 (0)