Skip to content

Conversation

@aidankmcalister
Copy link
Member

@aidankmcalister aidankmcalister commented Dec 13, 2025

Summary by CodeRabbit

  • New Features
    • Implemented an automated daily cleanup workflow that identifies and removes stale database projects from your system. Projects that remain inactive for more than 24 hours are automatically deleted to optimize storage and maintain overall system health. This new process runs automatically at midnight UTC every day.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 13, 2025

Walkthrough

Introduces a new Cloudflare Workers scheduled workflow to delete stale Prisma projects. A DeleteStaleProjectsWorkflow class fetches projects via API, filters those older than 24 hours, and deletes them. Integration updates the main worker to register the workflow and apply a daily cron schedule.

Changes

Cohort / File(s) Summary
Stale Workflow Implementation
create-db-worker/src/delete-stale-workflow.ts
New workflow class that fetches projects from Prisma API, identifies stale projects (>24 hours old), and deletes them one by one; includes type definitions for request/response structures.
Worker Integration
create-db-worker/src/index.ts
Imports and exports DeleteStaleProjectsWorkflow; adds it to Env interface; registers scheduled event handler with daily cron trigger to invoke the workflow.
Workflow Configuration
create-db-worker/wrangler.jsonc
Registers new "delete-stale-workflow" in workflows array with binding and class reference; configures daily cron schedule (0 0 * * *).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • API integration logic: Validate error handling for fetch failures, response validation, and HTTP status checking
  • Stale filtering logic: Verify the 24-hour threshold calculation and timestamp comparison are correct
  • INTEGRATION_TOKEN security: Confirm proper credential handling and Authorization header usage
  • Workflow registration: Ensure the cron expression, binding name, and class reference align across configuration and code
  • Empty params validation: Check if empty params {} is the intended contract for the scheduled trigger

Pre-merge checks

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'DR-5507 Delete workflow added' is vague and generic, using non-descriptive terms that don't clearly convey what type of workflow is being added or its purpose. Revise the title to be more specific about the workflow's purpose, such as 'Add DeleteStaleProjectsWorkflow to clean up old Prisma projects' or 'Implement scheduled workflow to delete stale projects'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Comment @coderabbitai help to get the list of available commands and usage tips.

@aidankmcalister aidankmcalister changed the title DC-5507 Delete workflow added DR-5507 Delete workflow added Dec 13, 2025
@github-actions
Copy link

Preview CLIs & Workers are live!

Test the CLIs locally under tag pr69-DC-5507-delete-stale-projects-workflow-20197005562:

npx create-db@pr69
npx create-pg@pr69
npx create-postgres@pr69

Worker URLs
• Create-DB Worker: https://create-db-temp.prisma.io
• Claim-DB Worker: https://create-db.prisma.io

These will live as long as this PR exists under tag pr69-DC-5507-delete-stale-projects-workflow-20197005562.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 13, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
claim-db-worker b3e9ce8 Commit Preview URL

Branch Preview URL
Dec 13 2025, 07:50 PM

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
create-db-worker/src/delete-stale-workflow.ts (2)

42-42: Consider wrapping JSON.parse in try/catch for better error messages.

If the API returns malformed JSON, this will throw a generic parsing error. Wrapping it provides clearer diagnostics.

-		const projects: ProjectsResponse = JSON.parse(res);
+		let projects: ProjectsResponse;
+		try {
+			projects = JSON.parse(res);
+		} catch (e) {
+			throw new Error(`Failed to parse projects response: ${e}`);
+		}

46-49: Invalid createdAt values will silently skip projects.

If createdAt is malformed, getTime() returns NaN and the comparison fails, excluding the project. This is safe but might mask data issues.

 		const staleProjects = projects.data.filter((project) => {
 			const createdAt = new Date(project.createdAt).getTime();
+			if (isNaN(createdAt)) {
+				console.warn(`Project ${project.id} has invalid createdAt: ${project.createdAt}`);
+				return false;
+			}
 			return now - createdAt > twentyFourHours;
 		});
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1f920a and b3e9ce8.

📒 Files selected for processing (3)
  • create-db-worker/src/delete-stale-workflow.ts (1 hunks)
  • create-db-worker/src/index.ts (2 hunks)
  • create-db-worker/wrangler.jsonc (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
create-db-worker/src/index.ts (3)
claim-db-worker/lib/env.ts (1)
  • Env (1-9)
claim-db-worker/worker-configuration.d.ts (1)
  • env (6913-6913)
create-db-worker/worker-configuration.d.ts (1)
  • env (6794-6794)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Workers Builds: claim-db-worker
  • GitHub Check: Workers Builds: create-db-worker
🔇 Additional comments (6)
create-db-worker/src/delete-stale-workflow.ts (1)

53-69: LGTM!

Each deletion is correctly wrapped in its own workflow step with a unique name, ensuring idempotency on retries. Sequential execution is appropriate for this use case.

create-db-worker/wrangler.jsonc (1)

17-25: LGTM!

The workflow binding and cron trigger are correctly configured. Daily execution at midnight UTC is appropriate for stale project cleanup.

create-db-worker/src/index.ts (4)

2-2: LGTM!

Import correctly references the new workflow module.


7-7: LGTM!

The Workflow type binding is correctly added to the Env interface, matching the wrangler.jsonc configuration.


14-14: LGTM!

Both workflow classes are correctly exported for Cloudflare to discover them.


199-202: LGTM!

The scheduled handler correctly logs the cron expression and uses ctx.waitUntil to create the workflow instance without blocking. The empty params object matches the workflow's Params type.

@aidankmcalister aidankmcalister merged commit 83b8fe6 into main Dec 14, 2025
6 checks passed
@aidankmcalister aidankmcalister deleted the DC-5507-delete-stale-projects-workflow branch December 14, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants