Repository navigation
feat(share): move existing shares into dfo-apis with a migration job - #86
Merged
Merged
Conversation
The share migration job reads the website's own share rows, places each
as the export did, keeps each owner's shw_ write token in share_token,
and calls dfo-apis' PUT /api/presentation/shares/{id}/import with only
the token's SHA-256. It holds the owner's user row FOR SHARE across the
call, so an account deletion either waits and takes the imported share
down or lands first and the job skips the share. The export and
token-import scripts are removed. apisFetch signs requests from a Cloud
Run job as well as a service, so the job calls dfo-apis with an ID token.
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.
The website's shares made before website#77 live in its own
sharetable, and dfo-apis now serves every share, so their/s/<id>and/embed/<id>links answer 404 until they move. The export and import scripts written for that move could not run in a deployed environment: Cloud SQL is reachable only inside the private network, the import read a local file and wrote a local token report, and the website image shipped no scripts. This PR replaces them with a Cloud Run job,dist/migrate-shares.cjs, that runs inside the network.migrateShares(db/share-migrate.ts) reads everysharerow withreadShares, places it with the export's rules (db/share-export.ts, unchanged), and callsPUT /api/presentation/shares/{id}/importon dfo-apis with the line andwrite_token_sha256. For an owned share it runs two transactions. The first reads the owner's token inshare_tokenor mints one and stores it withputShareToken, and commits, so a re-run reuses it. The second reads it withholdShareToken(src/lib/chat/shareTokens.ts), which holds the owner'suserrowFOR SHAREacross the call, the lockputShareTokenrelies on, so an account deletion either waits and then takes the imported share down or lands first and the job skips the share (owner_deleted). Only the digest leaves the website. A guest share sends a null digest. Each refusal printsshare <id>: <code> <detail>, a tally follows, and the job exits 1 when any share did not import or answer unchanged.apisFetchsigns a request whenCLOUD_RUN_JOBis set as well asK_SERVICE, so the job calls dfo-apis with an ID token as the service does. The deploy workflow pointsSHARE_MIGRATE_JOB_WEBSITEat each release image and now requires that variable, whichscripts/handoff.sh <env> websitein DevelopmentFinanceObservatory/infra writes once infra#129 has applied there. A prod deploy of this change therefore waits on infra#129 reaching prod. CI builds the bundle and checks it fails naming its first missing setting.scripts/export-shares.ts,scripts/import-share-tokens.tsanddb/share-token-import.tsare removed, anddocs/share-export.mdanddeploy/README.mddescribe the job.The job, and dfo-apis' import route and principal, exist for one migration per environment and are removed once prod is migrated.
Testing: lint, lint:css, typecheck,
pnpm testagainst Postgres 18 (2,171 passed), and every bundle build. The new tests cover a guest share, minting once and reusing on a re-run, the lock held during the call (a fence update times out with55P03), a fenced or deleted owner, the tally and exit code, and the HTTP mapping; each fails with its guard removed. The round trip against the dfo-apis local stack runs once the import route lands.