feat: add daily email usage (#97)

* add daily email usage

* remove console
This commit is contained in:
KM Koushik
2025-02-02 07:57:49 +11:00
committed by GitHub
parent 6b9696e715
commit f60c66acbe
9 changed files with 283 additions and 158 deletions

View File

@@ -0,0 +1,8 @@
-- CreateIndex
CREATE INDEX "Campaign_createdAt_idx" ON "Campaign"("createdAt" DESC);
-- CreateIndex
CREATE INDEX "Email_createdAt_idx" ON "Email"("createdAt" DESC);
-- CreateIndex
CREATE INDEX "EmailEvent_emailId_idx" ON "EmailEvent"("emailId");

View File

@@ -0,0 +1,22 @@
-- CreateEnum
CREATE TYPE "EmailUsageType" AS ENUM ('TRANSACTIONAL', 'MARKETING');
-- CreateTable
CREATE TABLE "DailyEmailUsage" (
"teamId" INTEGER NOT NULL,
"date" TEXT NOT NULL,
"type" "EmailUsageType" NOT NULL,
"domainId" INTEGER NOT NULL,
"delivered" INTEGER NOT NULL,
"opened" INTEGER NOT NULL,
"clicked" INTEGER NOT NULL,
"bounced" INTEGER NOT NULL,
"complained" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "DailyEmailUsage_pkey" PRIMARY KEY ("teamId","domainId","date","type")
);
-- AddForeignKey
ALTER TABLE "DailyEmailUsage" ADD CONSTRAINT "DailyEmailUsage_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,7 @@
-- AlterTable
ALTER TABLE "DailyEmailUsage" ADD COLUMN "sent" INTEGER NOT NULL DEFAULT 0,
ALTER COLUMN "delivered" SET DEFAULT 0,
ALTER COLUMN "opened" SET DEFAULT 0,
ALTER COLUMN "clicked" SET DEFAULT 0,
ALTER COLUMN "bounced" SET DEFAULT 0,
ALTER COLUMN "complained" SET DEFAULT 0;

View File

@@ -91,16 +91,17 @@ model User {
}
model Team {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
teamUsers TeamUser[]
domains Domain[]
apiKeys ApiKey[]
emails Email[]
contactBooks ContactBook[]
campaigns Campaign[]
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
teamUsers TeamUser[]
domains Domain[]
apiKeys ApiKey[]
emails Email[]
contactBooks ContactBook[]
campaigns Campaign[]
dailyEmailUsages DailyEmailUsage[]
}
enum Role {
@@ -203,6 +204,8 @@ model Email {
contactId String?
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
emailEvents EmailEvent[]
@@index([createdAt(sort: Desc)])
}
model EmailEvent {
@@ -212,6 +215,8 @@ model EmailEvent {
data Json?
createdAt DateTime @default(now())
email Email @relation(fields: [emailId], references: [id], onDelete: Cascade)
@@index([emailId])
}
model ContactBook {
@@ -277,4 +282,30 @@ model Campaign {
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@index([createdAt(sort: Desc)])
}
enum EmailUsageType {
TRANSACTIONAL
MARKETING
}
model DailyEmailUsage {
teamId Int
date String
type EmailUsageType
domainId Int
sent Int @default(0)
delivered Int @default(0)
opened Int @default(0)
clicked Int @default(0)
bounced Int @default(0)
complained Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@id([teamId, domainId, date, type])
}