diff --git a/apps/web/prisma/migrations/20261117010000_email_team_created_at_index/migration.sql b/apps/web/prisma/migrations/20261117010000_email_team_created_at_index/migration.sql new file mode 100644 index 000000000..bbbc2512d --- /dev/null +++ b/apps/web/prisma/migrations/20261117010000_email_team_created_at_index/migration.sql @@ -0,0 +1,6 @@ +-- CreateIndex +-- Built CONCURRENTLY so sending isn't blocked while it builds on a large +-- "Email" table. CONCURRENTLY can't run inside a transaction, so this must be +-- the only statement in the file. IF NOT EXISTS: on useSend cloud the index was +-- created by hand before this shipped. +CREATE INDEX CONCURRENTLY IF NOT EXISTS "Email_teamId_createdAt_idx" ON "Email"("teamId", "createdAt" DESC); diff --git a/apps/web/prisma/migrations/20261117010100_email_team_domain_created_at_index/migration.sql b/apps/web/prisma/migrations/20261117010100_email_team_domain_created_at_index/migration.sql new file mode 100644 index 000000000..8c595775a --- /dev/null +++ b/apps/web/prisma/migrations/20261117010100_email_team_domain_created_at_index/migration.sql @@ -0,0 +1,6 @@ +-- CreateIndex +-- Built CONCURRENTLY so sending isn't blocked while it builds on a large +-- "Email" table. CONCURRENTLY can't run inside a transaction, so this must be +-- the only statement in the file. IF NOT EXISTS: on useSend cloud the index was +-- created by hand before this shipped. +CREATE INDEX CONCURRENTLY IF NOT EXISTS "Email_teamId_domainId_createdAt_idx" ON "Email"("teamId", "domainId", "createdAt" DESC); diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma index 67e44c428..49e4c59ea 100644 --- a/apps/web/prisma/schema.prisma +++ b/apps/web/prisma/schema.prisma @@ -300,6 +300,11 @@ model Email { @@index([campaignId, contactId]) @@index([createdAt(sort: Desc)]) + // A team's emails, newest first: the dashboard email list and search, the + // public API's GET /emails (and its count), and the email export. + @@index([teamId, createdAt(sort: Desc)]) + // The same, filtered by domain (domain-restricted API keys, domain filter). + @@index([teamId, domainId, createdAt(sort: Desc)]) } model CampaignEmail {