Skip to content

feat(db): add automatic purge of expired terminated clusters#266

Merged
r2dedios merged 1 commit into
release-0.6from
feat/purge-expired-clusters
Jun 23, 2026
Merged

feat(db): add automatic purge of expired terminated clusters#266
r2dedios merged 1 commit into
release-0.6from
feat/purge-expired-clusters

Conversation

@r2dedios

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a purge_expired_clusters() SQL function that deletes terminated clusters older than a configurable retention period (default: 365 days) and refreshes materialized views
  • Adds a daily pg_cron job (0 0 * * *) to run the purge automatically
  • Adds CIQ_MAX_DATA_AGE env var to configure retention in both Compose and Helm deployments

Details

Terminated clusters and all their dependent data (instances, tags, expenses, events, schedules) accumulate indefinitely. This adds a database-level maintenance mechanism to purge stale data without exposing a destructive API endpoint.

The cascade chain handles cleanup automatically:

DELETE cluster → instances (CASCADE) → tags, expenses, target_instances (CASCADE)
                                     → events (trigger)
              → target_clusters (CASCADE) → schedules → action_runs (CASCADE)
              → events (trigger)

Files changed

File Change
db/sql/init.sql purge_expired_clusters() function
db/sql/cron.sql Daily pg_cron job
deployments/compose/compose-devel.yaml CIQ_MAX_DATA_AGE env var + override step
deployments/helm/cluster-iq/values.yaml database.maxDataAge setting
deployments/helm/cluster-iq/templates/database/job.yaml Env var + override step
deployments/helm/cluster-iq/templates/database/configmap-init.yaml SQL function + pg_cron job

Test plan

  • Deployed locally with CIQ_MAX_DATA_AGE=1 and verified SELECT purge_expired_clusters(1); removes terminated clusters
  • Verified cascade deletes dependent data (instances, tags, expenses, events)
  • Verified materialized views refresh after purge
  • Verified pg_cron job is registered via SELECT * FROM pg_cron_history();

@r2dedios r2dedios self-assigned this Jun 23, 2026
@r2dedios r2dedios added the enhancement New feature or request label Jun 23, 2026
@r2dedios r2dedios added this to the v0.6 milestone Jun 23, 2026
@r2dedios r2dedios linked an issue Jun 23, 2026 that may be closed by this pull request
@r2dedios r2dedios merged commit e955b5a into release-0.6 Jun 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define data lifetime variable

1 participant