Skip to content

[feat] Emails retention periods/cleanup #158

@jnettome

Description

@jnettome

Hey everyone,

I'm thinking about implementing a cleanup process for old email bodies, since our database is growing significantly due to storing all message content and attachments.

Do you have any recommendations for how to approach this? Or maybe a better solution based on typical project structures?

At the moment, I'm running a SQL query via cron just to get things working in my environment, but I plan to eventually turn this into a proper feature.

Thanks again!

async function cleanupEmailBodies() {
  const result = await db.$executeRaw`
    UPDATE "Email"
    SET "text" = NULL,
        "html" = NULL
    WHERE "createdAt" < NOW() - INTERVAL '90 days'
    AND ("text" IS NOT NULL OR "html" IS NOT NULL);
  `;

  console.log(`[Cleanup] Emails cleaned: ${result}`);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions