Repository navigation
feat(exports): persist daily export records and claims in Postgres - #1664
Merged
greatest0fallt1me merged 2 commits intoNov 24, 2026
Merged
Conversation
- Add PostgresExportStore, a DeveloperExportStore on developer_exports and a new developer_export_claims table. Reason: ReportExporterService used InMemoryExportStore in every deployment, so a restart lost export history and two instances could export the same developer day. Consequence: outside demo mode and tests, export records and daily claims are stored in Postgres. - claimDay is one INSERT ... ON CONFLICT statement. A claimed day is always refused, and a completed day is refused unless forced. Consequence: two concurrent claims cannot both succeed. This depends on Postgres row locking and is not yet verified against a live database. - Add migration 0033 with a primary key on (developer_id, day) for claims and a unique index on developer_exports (developer_id, s3_key), with a down migration. Consequence: re-saving the same artifact replaces its row instead of duplicating it. The down migration drops the claims table and the index, and carries the destructive-approved marker for CalloraOrg#1557. - createAppExports defaults to PostgresExportStore, and to InMemoryExportStore in demo mode and under NODE_ENV=test. Consequence: existing callers are unchanged. Standard deployments must apply migration 0033 before enabling exports. - Add mocked SQL tests for PostgresExportStore, and a behaviour contract that runs against the in-memory store and against Postgres when DATABASE_URL is set. Consequence: the Postgres contract is skipped unless DATABASE_URL is provided. Typecheck, lint and jest have not been run. - Document the store in docs/scheduled-exports.md and add a CHANGELOG entry. Closes CalloraOrg#1557
|
@salienne 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! 🚀 |
Contributor
|
Thanks @salienne! We resolved the merge conflicts on our side and merged this. 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ReportExporterServiceusedInMemoryExportStorein every deployment. Export history was lost on restart, and two instances could export the same developer and day. This PR addsPostgresExportStoreon the existingdeveloper_exportstable, plus a newdeveloper_export_claimstable for atomic daily claims.PostgresExportStoreimplementsDeveloperExportStore.saveupserts on(developer_id, s3_key).listByDeveloperkeeps the expiry filter, the format filter, the(exported_at DESC, id DESC)keyset cursor, and the rule that a cursor takes precedence over offset.claimDayis oneINSERT ... ON CONFLICT DO UPDATE ... WHEREstatement. A claimed day is always refused. A completed day is refused unless forced.completeDayandreleaseDaymatch the in-memory semantics.0033_developer_export_claimsadds the claims table and a unique index ondeveloper_exports (developer_id, s3_key), with a down migration.createAppExportsusesPostgresExportStoreby default, andInMemoryExportStorein demo mode and underNODE_ENV=test.What breaks if this is wrong
claimDaycould let two instances export the same day, or block a day that should export. The SQL decides the transition in one statement, so the guard is the single point to check.COLLATE "C".Deployment and rollback
0033_developer_export_claims.sqlbefore enabling exports.0033_developer_export_claims.down.sql. It drops the claims table and the unique index, so claim state is lost. The file carriesdestructive-approved: #1557.Verification
Not run. This environment has no clone, no Node install, and no database.
postgresExportStore.test.tscheck the statements, bound parameters, and result mapping.exportStoreContract.test.tsruns the same behaviour table againstInMemoryExportStore. It runs againstPostgresExportStoreonly whenDATABASE_URLis set. That is the only check of the concurrency guarantee, and it has not run.npm test,npm run typecheck,npm run db:check-migrations, lint.Acceptance criteria
GET /api/exportslists previously saved records. Not verified against a database.claimDaycalls: exactly one returnstrue. Covered by the contract test, which needsDATABASE_URL. Not run.saveof the same developer ands3Keyreplaces the row. Covered by the in-memory contract and the SQL upsert.Not in this PR
docs/scheduled-exports.mdinstead.Closes #1557