Repository navigation
cold-store: nightly Turso exports via HTTP APIs - #993
Conversation
Discover databases from the Turso Platform API, mint a per-database auth token, download the SQL dump from each database's own libsql /dump endpoint with curl, rebuild a standalone SQLite file, require integrity_check ok, gzip, and file with put-backup turso. Skips with a one-line notice (exit 0) when TURSO_PLATFORM_API_TOKEN is unset; per-database failures are named loudly and exit non-zero after the rest are attempted. Wired into nightly-backup.sh before prune-backups so same-night retention covers the new files.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8b03c2ca4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| echo "turso export: ERROR: ${name}: gzip failed" >&2 | ||
| return 1 | ||
| fi | ||
| if ! "${COLD_STORE}" put-backup turso "${db_file}.gz"; then |
There was a problem hiding this comment.
Retain exports separately for each Turso database
When the organization contains multiple databases, filing every export under turso makes their backups compete for a single retention slot. In cold_store.py, prune_backups() passes the entire Turso folder to _retention_plan(), which keeps only the newest file per day/week/month without distinguishing database names. Because nightly-backup.sh runs prune-backups --apply immediately after this script, even the first successful nightly run trashes all but one of that night's database exports. Group retention by the source database, or file all databases together as one nightly backup, before enabling this integration.
Useful? React with 👍 / 👎.
Adds the Turso stream to the cold store's nightly backup, with no
tursoCLI dependency.scripts/export-turso.sh(new): discovers databases from the Turso Platform API (GET /v1/organizations/<org>/databases, items carryName/Hostname), mints a per-database auth token (POST .../databases/<name>/auth/tokens), downloads the SQL dump from each database's own libsql endpoint (GET https://<hostname>/dump) with curl, rebuilds a standalone SQLite file with python3, requiresPRAGMA integrity_check= ok, gzips -6, and files it viacold-store put-backup turso.TURSO_PLATFORM_API_TOKENunset → printsturso export: skipped (TURSO_PLATFORM_API_TOKEN not set)and exits 0 — a missing Turso setup never fails the nightly, and the skip is never silent.TURSO_ORG(defaultdezren39),TURSO_API_BASE,TURSO_DUMP_BASE,COLD_STORE_BIN(cf.COLD_STORE_S3_BASE).scripts/nightly-backup.sh: the Turso step runs afterbackup-supabaseand beforeprune-backups --apply, so same-night retention covers the new Turso files.Tests:
TestTursoExportScript(3 tests, fully offline) against a fake Turso HTTP server (ThreadingHTTPServer, the repo's fake style) + a stubcold-storeexecutable: both fake DBs filed with integrity-verified .db.gz payloads and no token material in output; missing-token skip line + exit 0 + zero filings; one DB's dump returning 500 still files the other and exits non-zero. Full suite: 58 tests (55 + 3), 1 pre-existing skip. shellcheck + shfmt + prettier + ruff format clean.Need help on this PR? Tag
@codesmith-botwith what you need.