feat: add daily email usage (#97)
* add daily email usage * remove console
This commit is contained in:
@@ -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");
|
@@ -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;
|
@@ -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;
|
@@ -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])
|
||||
}
|
||||
|
Reference in New Issue
Block a user