Skip to content

feat(deployments): soft-delete, correlation IDs, graceful shutdown, analytics optimization#685

Merged
temma02 merged 1 commit into
StellerCraft:mainfrom
joel-metal:feat/issues-597-600-deployment-improvements
May 28, 2026
Merged

feat(deployments): soft-delete, correlation IDs, graceful shutdown, analytics optimization#685
temma02 merged 1 commit into
StellerCraft:mainfrom
joel-metal:feat/issues-597-600-deployment-improvements

Conversation

@joel-metal
Copy link
Copy Markdown
Contributor

@joel-metal joel-metal commented May 28, 2026

Summary

Changes

File Change
supabase/migrations/010_deployment_soft_delete.sql Add deleted_at column + partial indexes
supabase/migrations/011_analytics_query_optimization.sql Composite indexes + get_analytics_summary() function
apps/backend/src/app/api/deployments/[id]/route.ts Soft-delete on DELETE; filter tombstoned on GET
apps/backend/src/app/api/deployments/[id]/restore/route.ts New restore endpoint
apps/backend/src/app/api/cron/purge-tombstoned-deployments/route.ts New purge cron
apps/backend/src/app/api/deployments/route.ts Filter tombstoned on list/count; 503 during drain
apps/backend/src/lib/api/with-auth.ts withDeploymentAuth excludes tombstoned records
apps/backend/src/lib/shutdown-manager.ts Drain state + in-flight tracker
apps/backend/src/instrumentation.ts Signal handlers
apps/backend/src/services/analytics.service.ts Single-pass aggregation + 60 s cache
apps/backend/src/app/api/deployments/[id]/analytics/route.ts Structured logging + correlationId in errors

Closes

Closes #597
closes #598
closes #599
closes #600

🤖 Generated with Claude Code

…nalytics optimization

Closes StellerCraft#597, StellerCraft#598, StellerCraft#599, StellerCraft#600

StellerCraft#597 – Soft-delete & tombstone pattern
- Add deleted_at tombstone column via migration 010
- Exclude soft-deleted records from all default queries (list, get, count, withDeploymentAuth)
- Soft-delete on DELETE instead of hard-delete; external cleanup remains best-effort
- POST /api/deployments/[id]/restore within the retention window (DEPLOYMENT_TOMBSTONE_RETENTION_DAYS, default 30)
- Cron /api/cron/purge-tombstoned-deployments permanently removes records past the window

StellerCraft#598 – Structured logging correlation IDs
- Analytics route now uses log/correlationId from withDeploymentAuth context
- correlationId included in all 5xx error responses for support correlation
- Replaces raw console.error with structured log.error in analytics handler

StellerCraft#599 – Graceful shutdown for in-flight deployments
- shutdown-manager.ts: isDraining / trackOperation / drain() with configurable timeout
- instrumentation.ts: SIGTERM/SIGINT handlers that call drain() before process.exit
- POST /api/deployments returns 503 with Retry-After during drain

StellerCraft#600 – Analytics aggregation query optimization
- Migration 011: composite indexes on (deployment_id, metric_type, metric_value)
  and (deployment_id, recorded_at DESC)
- get_analytics_summary() DB function replaces 3 separate full-table scans
  with a single GROUP BY aggregation pass via supabase.rpc()
- 60-second in-process cache (summaryCache) for high-frequency dashboard polls;
  invalidated on every write

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@joel-metal Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@temma02 temma02 merged commit 91bdc0e into StellerCraft:main May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants