feat: batch campaigns (#227)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
-- AlterEnum
|
||||
-- This migration adds more than one value to an enum.
|
||||
-- With PostgreSQL versions 11 and earlier, this is not possible
|
||||
-- in a single migration. This can be worked around by creating
|
||||
-- multiple migrations, each migration adding only one value to
|
||||
-- the enum.
|
||||
|
||||
|
||||
ALTER TYPE "CampaignStatus" ADD VALUE 'RUNNING';
|
||||
ALTER TYPE "CampaignStatus" ADD VALUE 'PAUSED';
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Campaign" ADD COLUMN "batchSize" INTEGER NOT NULL DEFAULT 500,
|
||||
ADD COLUMN "batchWindowMinutes" INTEGER NOT NULL DEFAULT 0,
|
||||
ADD COLUMN "lastCursor" TEXT,
|
||||
ADD COLUMN "lastSentAt" TIMESTAMP(3),
|
||||
ADD COLUMN "scheduledAt" TIMESTAMP(3);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "CampaignEmail" (
|
||||
"campaignId" TEXT NOT NULL,
|
||||
"contactId" TEXT NOT NULL,
|
||||
"emailId" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "CampaignEmail_pkey" PRIMARY KEY ("campaignId","contactId")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Campaign_status_scheduledAt_idx" ON "Campaign"("status", "scheduledAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Contact_contactBookId_id_idx" ON "Contact"("contactBookId", "id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Email_campaignId_contactId_idx" ON "Email"("campaignId", "contactId");
|
||||
@@ -263,9 +263,19 @@ model Email {
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
emailEvents EmailEvent[]
|
||||
|
||||
@@index([campaignId, contactId])
|
||||
@@index([createdAt(sort: Desc)])
|
||||
}
|
||||
|
||||
model CampaignEmail {
|
||||
campaignId String
|
||||
contactId String
|
||||
emailId String
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@id([campaignId, contactId])
|
||||
}
|
||||
|
||||
model EmailEvent {
|
||||
id String @id @default(cuid())
|
||||
emailId String
|
||||
@@ -320,44 +330,53 @@ model Contact {
|
||||
contactBook ContactBook @relation(fields: [contactBookId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([contactBookId, email])
|
||||
@@index([contactBookId, id])
|
||||
}
|
||||
|
||||
enum CampaignStatus {
|
||||
DRAFT
|
||||
SCHEDULED
|
||||
RUNNING
|
||||
PAUSED
|
||||
SENT
|
||||
}
|
||||
|
||||
model Campaign {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
teamId Int
|
||||
from String
|
||||
cc String[]
|
||||
bcc String[]
|
||||
replyTo String[]
|
||||
domainId Int
|
||||
subject String
|
||||
previewText String?
|
||||
html String?
|
||||
content String?
|
||||
contactBookId String?
|
||||
total Int @default(0)
|
||||
sent Int @default(0)
|
||||
delivered Int @default(0)
|
||||
opened Int @default(0)
|
||||
clicked Int @default(0)
|
||||
unsubscribed Int @default(0)
|
||||
bounced Int @default(0)
|
||||
hardBounced Int @default(0)
|
||||
complained Int @default(0)
|
||||
status CampaignStatus @default(DRAFT)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
teamId Int
|
||||
from String
|
||||
cc String[]
|
||||
bcc String[]
|
||||
replyTo String[]
|
||||
domainId Int
|
||||
subject String
|
||||
previewText String?
|
||||
html String?
|
||||
content String?
|
||||
contactBookId String?
|
||||
scheduledAt DateTime?
|
||||
total Int @default(0)
|
||||
sent Int @default(0)
|
||||
delivered Int @default(0)
|
||||
opened Int @default(0)
|
||||
clicked Int @default(0)
|
||||
unsubscribed Int @default(0)
|
||||
bounced Int @default(0)
|
||||
hardBounced Int @default(0)
|
||||
complained Int @default(0)
|
||||
status CampaignStatus @default(DRAFT)
|
||||
batchSize Int @default(500)
|
||||
batchWindowMinutes Int @default(0)
|
||||
lastCursor String?
|
||||
lastSentAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([createdAt(sort: Desc)])
|
||||
@@index([status, scheduledAt])
|
||||
}
|
||||
|
||||
model Template {
|
||||
|
||||
Reference in New Issue
Block a user