Skip to content

feat(exports): persist scheduled exports in Postgres - #1661

Open
devogechukwu wants to merge 1 commit into
CalloraOrg:mainfrom
devogechukwu:feat/postgres-schedule-store
Open

devogechukwu wants to merge 1 commit into
CalloraOrg:mainfrom
devogechukwu:feat/postgres-schedule-store

Conversation

@devogechukwu

Copy link
Copy Markdown

Summary

Persists scheduled export definitions (including encrypted S3 secrets, lastRunAt, and nextRunAt) in PostgreSQL so they survive restarts/deploys.

Changes

  • Migration: Added migrations/0033_export_schedules.sql and migrations/0033_export_schedules.down.sql creating export_schedules with indexes on (enabled, next_run_at) and (developer_id).
  • Shared Encryption Helpers: Extracted deriveScheduleEncryptionKey, encryptSchedule, and decryptSchedule (AES-256-GCM, v1.<iv>.<tag>.<data>) in src/services/scheduledExports.ts so both stores share the same implementation.
  • Postgres Store: Added PostgresScheduleStore in src/services/postgresScheduleStore.ts implementing ScheduleStore:
    • list() ordered by created_at ASC
    • getById() and save() with encrypted s3_secret_access_key
    • update() as a read-merge-write that bumps updated_at and returns undefined for unknown IDs
    • Plaintext secrets are never passed to SQL queries or returned in errors
  • Wiring: Updated createAppExports in src/services/appExports.ts to use PostgresScheduleStore when a Postgres pool is available (outside demo mode/tests), keeping InMemoryScheduleStore for demo mode and unit tests.
  • Tests: Added src/services/postgresScheduleStore.test.ts with shared contract tests for both InMemoryScheduleStore and PostgresScheduleStore, plus pg-mem persistence, encryption, wrong-key decryption failure, ordering, missing-id update, disabled schedules, and runDueSchedules tests.

Closes #1558

@drips-wave

drips-wave Bot commented Nov 23, 2026

Copy link
Copy Markdown

@devogechukwu 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

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.

Persist scheduled export schedules in Postgres instead of InMemoryScheduleStore

1 participant