Phase9
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
-- Phase 9: WHMCS integration and billing suspension
|
||||
|
||||
CREATE TYPE "WhmcsServiceStatus" AS ENUM ('PENDING', 'ACTIVE', 'SUSPENDED', 'TERMINATED');
|
||||
CREATE TYPE "IntegrationOperationStatus" AS ENUM ('COMPLETED', 'FAILED');
|
||||
|
||||
ALTER TABLE "game_servers"
|
||||
ADD COLUMN IF NOT EXISTS "billingSuspendedAt" TIMESTAMPTZ(3),
|
||||
ADD COLUMN IF NOT EXISTS "billingSuspendReason" TEXT;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "whmcs_installations" (
|
||||
"id" TEXT NOT NULL,
|
||||
"integrationId" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"apiSecret" TEXT NOT NULL,
|
||||
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||
"metadata" JSONB,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
|
||||
CONSTRAINT "whmcs_installations_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_installations_integrationId_key"
|
||||
ON "whmcs_installations"("integrationId");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "whmcs_client_links" (
|
||||
"id" TEXT NOT NULL,
|
||||
"installationId" TEXT NOT NULL,
|
||||
"externalClientId" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
|
||||
CONSTRAINT "whmcs_client_links_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_client_links_userId_key" ON "whmcs_client_links"("userId");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_client_links_installationId_externalClientId_key"
|
||||
ON "whmcs_client_links"("installationId", "externalClientId");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "whmcs_service_links" (
|
||||
"id" TEXT NOT NULL,
|
||||
"installationId" TEXT NOT NULL,
|
||||
"externalServiceId" TEXT NOT NULL,
|
||||
"serverId" TEXT NOT NULL,
|
||||
"externalProductId" TEXT,
|
||||
"status" "WhmcsServiceStatus" NOT NULL DEFAULT 'PENDING',
|
||||
"suspendedAt" TIMESTAMPTZ(3),
|
||||
"terminatedAt" TIMESTAMPTZ(3),
|
||||
"metadata" JSONB,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
|
||||
CONSTRAINT "whmcs_service_links_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_service_links_serverId_key" ON "whmcs_service_links"("serverId");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "whmcs_service_links_installationId_externalServiceId_key"
|
||||
ON "whmcs_service_links"("installationId", "externalServiceId");
|
||||
CREATE INDEX IF NOT EXISTS "whmcs_service_links_installationId_status_idx"
|
||||
ON "whmcs_service_links"("installationId", "status");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "integration_operations" (
|
||||
"id" TEXT NOT NULL,
|
||||
"installationId" TEXT NOT NULL,
|
||||
"idempotencyKey" TEXT NOT NULL,
|
||||
"operation" TEXT NOT NULL,
|
||||
"externalRef" TEXT,
|
||||
"status" "IntegrationOperationStatus" NOT NULL DEFAULT 'COMPLETED',
|
||||
"result" JSONB,
|
||||
"error" TEXT,
|
||||
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "integration_operations_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "integration_operations_idempotencyKey_key"
|
||||
ON "integration_operations"("idempotencyKey");
|
||||
CREATE INDEX IF NOT EXISTS "integration_operations_installationId_createdAt_idx"
|
||||
ON "integration_operations"("installationId", "createdAt");
|
||||
|
||||
ALTER TABLE "whmcs_client_links"
|
||||
ADD CONSTRAINT "whmcs_client_links_installationId_fkey"
|
||||
FOREIGN KEY ("installationId") REFERENCES "whmcs_installations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE "whmcs_client_links"
|
||||
ADD CONSTRAINT "whmcs_client_links_userId_fkey"
|
||||
FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "whmcs_service_links"
|
||||
ADD CONSTRAINT "whmcs_service_links_installationId_fkey"
|
||||
FOREIGN KEY ("installationId") REFERENCES "whmcs_installations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE "whmcs_service_links"
|
||||
ADD CONSTRAINT "whmcs_service_links_serverId_fkey"
|
||||
FOREIGN KEY ("serverId") REFERENCES "game_servers"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "integration_operations"
|
||||
ADD CONSTRAINT "integration_operations_installationId_fkey"
|
||||
FOREIGN KEY ("installationId") REFERENCES "whmcs_installations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -135,6 +135,18 @@ enum DnsRecordStatus {
|
||||
REMOVED
|
||||
}
|
||||
|
||||
enum WhmcsServiceStatus {
|
||||
PENDING
|
||||
ACTIVE
|
||||
SUSPENDED
|
||||
TERMINATED
|
||||
}
|
||||
|
||||
enum IntegrationOperationStatus {
|
||||
COMPLETED
|
||||
FAILED
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
@@ -156,6 +168,7 @@ model User {
|
||||
passwordResetTokens PasswordResetToken[]
|
||||
totpCredential TotpCredential?
|
||||
creditWallet CreditWallet?
|
||||
whmcsClientLink WhmcsClientLink?
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
@@ -300,6 +313,8 @@ model GameServer {
|
||||
lastMeteredAt DateTime? @db.Timestamptz(3)
|
||||
joinSlug String? @unique
|
||||
joinToStartEnabled Boolean @default(true)
|
||||
billingSuspendedAt DateTime? @db.Timestamptz(3)
|
||||
billingSuspendReason String?
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @db.Timestamptz(3)
|
||||
|
||||
@@ -316,6 +331,7 @@ model GameServer {
|
||||
startQueueEntry ServerStartQueueEntry?
|
||||
usageRecords UsageRecord[]
|
||||
dnsRecords ServerDnsRecord[]
|
||||
whmcsServiceLink WhmcsServiceLink?
|
||||
|
||||
@@index([userId])
|
||||
@@index([nodeId])
|
||||
@@ -684,3 +700,73 @@ model ServerDnsRecord {
|
||||
@@index([fqdn])
|
||||
@@map("server_dns_records")
|
||||
}
|
||||
|
||||
model WhmcsInstallation {
|
||||
id String @id @default(uuid())
|
||||
integrationId String @unique
|
||||
name String
|
||||
apiSecret String
|
||||
isActive Boolean @default(true)
|
||||
metadata Json?
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @db.Timestamptz(3)
|
||||
|
||||
clientLinks WhmcsClientLink[]
|
||||
serviceLinks WhmcsServiceLink[]
|
||||
operations IntegrationOperation[]
|
||||
|
||||
@@map("whmcs_installations")
|
||||
}
|
||||
|
||||
model WhmcsClientLink {
|
||||
id String @id @default(uuid())
|
||||
installationId String
|
||||
externalClientId String
|
||||
userId String @unique
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @db.Timestamptz(3)
|
||||
|
||||
installation WhmcsInstallation @relation(fields: [installationId], references: [id], onDelete: Cascade)
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([installationId, externalClientId])
|
||||
@@map("whmcs_client_links")
|
||||
}
|
||||
|
||||
model WhmcsServiceLink {
|
||||
id String @id @default(uuid())
|
||||
installationId String
|
||||
externalServiceId String
|
||||
serverId String @unique
|
||||
externalProductId String?
|
||||
status WhmcsServiceStatus @default(PENDING)
|
||||
suspendedAt DateTime? @db.Timestamptz(3)
|
||||
terminatedAt DateTime? @db.Timestamptz(3)
|
||||
metadata Json?
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @db.Timestamptz(3)
|
||||
|
||||
installation WhmcsInstallation @relation(fields: [installationId], references: [id], onDelete: Cascade)
|
||||
server GameServer @relation(fields: [serverId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([installationId, externalServiceId])
|
||||
@@index([installationId, status])
|
||||
@@map("whmcs_service_links")
|
||||
}
|
||||
|
||||
model IntegrationOperation {
|
||||
id String @id @default(uuid())
|
||||
installationId String
|
||||
idempotencyKey String @unique
|
||||
operation String
|
||||
externalRef String?
|
||||
status IntegrationOperationStatus @default(COMPLETED)
|
||||
result Json?
|
||||
error String?
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||
|
||||
installation WhmcsInstallation @relation(fields: [installationId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([installationId, createdAt])
|
||||
@@map("integration_operations")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user