From a7aa8bf5a90f4a87a8c10353eec1600f9c5b4f9c Mon Sep 17 00:00:00 2001 From: maaz519 Date: Wed, 27 May 2026 17:07:39 +0530 Subject: [PATCH] feat(schema): Account model with AccountStatus enum, optional Group.accountId Adds Account model (platform, jid, sessionPath, displayName, status) with AccountStatus enum (ACTIVE/DISCONNECTED/BANNED) and optional accountId FK on Group for multi-account WhatsApp session tracking. Co-Authored-By: Claude Sonnet 4.6 --- .../migration.sql | 25 +++++++++++++++++++ apps/api/prisma/schema.prisma | 24 +++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 apps/api/prisma/migrations/20260527113634_add_account_model/migration.sql diff --git a/apps/api/prisma/migrations/20260527113634_add_account_model/migration.sql b/apps/api/prisma/migrations/20260527113634_add_account_model/migration.sql new file mode 100644 index 0000000..6eb3a6a --- /dev/null +++ b/apps/api/prisma/migrations/20260527113634_add_account_model/migration.sql @@ -0,0 +1,25 @@ +-- CreateEnum +CREATE TYPE "AccountStatus" AS ENUM ('ACTIVE', 'DISCONNECTED', 'BANNED'); + +-- AlterTable +ALTER TABLE "Group" ADD COLUMN "accountId" TEXT; + +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL, + "platform" TEXT NOT NULL, + "jid" TEXT NOT NULL, + "sessionPath" TEXT NOT NULL, + "displayName" TEXT, + "status" "AccountStatus" NOT NULL DEFAULT 'ACTIVE', + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Account_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_platform_jid_key" ON "Account"("platform", "jid"); + +-- AddForeignKey +ALTER TABLE "Group" ADD CONSTRAINT "Group_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index 2f72ab6..5f03b6b 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -4,7 +4,7 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") + url = env("../../../DATABASE_URL") } model Group { @@ -14,6 +14,8 @@ model Group { name String description String? isActive Boolean @default(true) + accountId String? + account Account? @relation(fields: [accountId], references: [id]) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -91,3 +93,23 @@ model ConsentRecord { @@unique([groupId, memberJid, consentType]) } + +enum AccountStatus { + ACTIVE + DISCONNECTED + BANNED +} + +model Account { + id String @id @default(cuid()) + platform String + jid String + sessionPath String + displayName String? + status AccountStatus @default(ACTIVE) + groups Group[] + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + @@unique([platform, jid]) +}