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 <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||||
@@ -4,7 +4,7 @@ generator client {
|
|||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "postgresql"
|
||||||
url = env("DATABASE_URL")
|
url = env("../../../DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
model Group {
|
model Group {
|
||||||
@@ -14,6 +14,8 @@ model Group {
|
|||||||
name String
|
name String
|
||||||
description String?
|
description String?
|
||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
|
accountId String?
|
||||||
|
account Account? @relation(fields: [accountId], references: [id])
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
|
||||||
@@ -91,3 +93,23 @@ model ConsentRecord {
|
|||||||
|
|
||||||
@@unique([groupId, memberJid, consentType])
|
@@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])
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user