From 146e479e1b3dfdd3f90326b3a3fbebdcbcc1886b Mon Sep 17 00:00:00 2001 From: Jose Rodrigues Date: Fri, 28 Feb 2025 10:05:45 -0300 Subject: [PATCH 1/3] feat: add unique index on chat to allow update chat label --- .../20250228130127_add_unique_chat/migration.sql | 8 ++++++++ prisma/postgresql-migrations/migration_lock.toml | 2 +- prisma/postgresql-schema.prisma | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 prisma/postgresql-migrations/20250228130127_add_unique_chat/migration.sql diff --git a/prisma/postgresql-migrations/20250228130127_add_unique_chat/migration.sql b/prisma/postgresql-migrations/20250228130127_add_unique_chat/migration.sql new file mode 100644 index 00000000..077b6929 --- /dev/null +++ b/prisma/postgresql-migrations/20250228130127_add_unique_chat/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - A unique constraint covering the columns `[instanceId,remoteJid]` on the table `Chat` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateIndex +CREATE UNIQUE INDEX "Chat_instanceId_remoteJid_key" ON "Chat"("instanceId", "remoteJid"); diff --git a/prisma/postgresql-migrations/migration_lock.toml b/prisma/postgresql-migrations/migration_lock.toml index fbffa92c..648c57fd 100644 --- a/prisma/postgresql-migrations/migration_lock.toml +++ b/prisma/postgresql-migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) +# It should be added in your version-control system (e.g., Git) provider = "postgresql" \ No newline at end of file diff --git a/prisma/postgresql-schema.prisma b/prisma/postgresql-schema.prisma index a9782ce5..28ffa751 100644 --- a/prisma/postgresql-schema.prisma +++ b/prisma/postgresql-schema.prisma @@ -125,6 +125,8 @@ model Chat { Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String unreadMessages Int @default(0) + + @@unique([instanceId, remoteJid]) @@index([instanceId]) @@index([remoteJid]) } @@ -168,6 +170,7 @@ model Message { sessionId String? session IntegrationSession? @relation(fields: [sessionId], references: [id]) + @@index([instanceId]) } @@ -183,6 +186,7 @@ model MessageUpdate { messageId String Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String + @@index([instanceId]) @@index([messageId]) } @@ -199,6 +203,7 @@ model Webhook { updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique + @@index([instanceId]) } @@ -269,6 +274,7 @@ model Setting { updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique + @@index([instanceId]) } From 16658baf99e54d965d95e13539dfe7d761144e14 Mon Sep 17 00:00:00 2001 From: Jose Rodrigues Date: Fri, 28 Feb 2025 10:16:16 -0300 Subject: [PATCH 2/3] feat: return labels in findChats --- src/api/services/channel.service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/api/services/channel.service.ts b/src/api/services/channel.service.ts index 0f30f0c9..cf03fc3e 100644 --- a/src/api/services/channel.service.ts +++ b/src/api/services/channel.service.ts @@ -702,6 +702,7 @@ export class ChannelStartupService { ) as "updatedAt", "Chat"."createdAt" as "windowStart", "Chat"."createdAt" + INTERVAL '24 hours' as "windowExpires", + "Chat"."labels" as "labels", CASE WHEN "Chat"."createdAt" + INTERVAL '24 hours' > NOW() THEN true ELSE false @@ -764,6 +765,7 @@ export class ChannelStartupService { windowExpires: contact.windowExpires, windowActive: contact.windowActive, lastMessage: lastMessage ? this.cleanMessageData(lastMessage) : undefined, + labels: contact.labels, }; }); From eba1dae358800c7d630483d9f096a2c97ba921b9 Mon Sep 17 00:00:00 2001 From: Jose Rodrigues Date: Fri, 28 Feb 2025 10:30:22 -0300 Subject: [PATCH 3/3] chore: remove indentation not necessary --- prisma/postgresql-migrations/migration_lock.toml | 2 +- prisma/postgresql-schema.prisma | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/prisma/postgresql-migrations/migration_lock.toml b/prisma/postgresql-migrations/migration_lock.toml index 648c57fd..fbffa92c 100644 --- a/prisma/postgresql-migrations/migration_lock.toml +++ b/prisma/postgresql-migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually -# It should be added in your version-control system (e.g., Git) +# It should be added in your version-control system (i.e. Git) provider = "postgresql" \ No newline at end of file diff --git a/prisma/postgresql-schema.prisma b/prisma/postgresql-schema.prisma index 28ffa751..090d4620 100644 --- a/prisma/postgresql-schema.prisma +++ b/prisma/postgresql-schema.prisma @@ -170,7 +170,6 @@ model Message { sessionId String? session IntegrationSession? @relation(fields: [sessionId], references: [id]) - @@index([instanceId]) } @@ -186,7 +185,6 @@ model MessageUpdate { messageId String Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String - @@index([instanceId]) @@index([messageId]) } @@ -203,7 +201,6 @@ model Webhook { updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique - @@index([instanceId]) } @@ -274,7 +271,6 @@ model Setting { updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String @unique - @@index([instanceId]) }