Add direct Turso database migration - #1923
Conversation
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 26 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds an interactive ChangesTurso migration and cancellation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant MigrationCLI
participant TursoAPI
participant Snapshot
participant Upload
User->>MigrationCLI: Enter source and destination details
MigrationCLI->>TursoAPI: Check destination and create upload-seeded database
MigrationCLI->>Snapshot: Create and verify SQLite snapshot
MigrationCLI->>Upload: Stream snapshot with database credentials
Upload-->>MigrationCLI: Return upload response
MigrationCLI-->>User: Print DB_URL and DB_TOKEN
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2365dd8454
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f54752ae86
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e79bcdd180
ℹ️ 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".
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/turso-migration-lib.ts`:
- Around line 202-205: Update the environment callback passed to
readSnapshotRequest so it explicitly handles only DB_URL and the expected token
key, returning dbUrl or dbToken respectively; throw an error for any unexpected
key instead of defaulting to dbToken.
In `@test/scripts/termination-signals.test.ts`:
- Around line 9-24: Extend the termination-signal tests around
expectBothTerminationSignals to stub the listener registration method so it
throws, then invoke onTerminationSignals and offTerminationSignals and assert
both complete without throwing. Cover the fallback catch branch in
scripts/termination-signals.ts while preserving the existing successful-call
assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 4a2c6676-9ef1-48dc-9f72-4a1e844928fe
📒 Files selected for processing (23)
AGENTS.mdREADME.mddeno.jsonscripts/audit-equivalent-mutants.tsscripts/database-snapshot-lib.tsscripts/mutation/child-process.tsscripts/mutation/isolation.tsscripts/mutation/runner.tsscripts/termination-signals.tsscripts/turso-migration-file.tsscripts/turso-migration-lib.tsscripts/turso-migration.tssrc/shared/turso-api.tstest/integration/turso-api-management.test.tstest/scripts/database-snapshot-safety.test.tstest/scripts/database-snapshot.test.tstest/scripts/mutation-child-process.test.tstest/scripts/termination-signals.test.tstest/scripts/turso-migration-file.test.tstest/scripts/turso-migration.test.tstest/shared/slug.test.tstest/test-utils/turso-api.tstest/test-utils/turso-migration.ts
💤 Files with no reviewable changes (2)
- test/shared/slug.test.ts
- scripts/mutation/child-process.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f0991a6852
ℹ️ 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".
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/shared/turso-api.ts (1)
196-201: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winClean up the database returned by the create response.
On a name mismatch, cleanup deletes the requested slug rather than
database.Name. This can leave the created destination behind and, after a concurrent creation, delete an unrelated database with the requested name.
src/shared/turso-api.ts#L196-L201: passdatabase.NametocleanUpFailedCreatein the mismatch branch.test/integration/turso-api-management.test.ts#L208-L232: expect the DELETE request to target the returned database name.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/shared/turso-api.ts` around lines 196 - 201, Update the name-mismatch branch in cleanUpFailedCreate usage within src/shared/turso-api.ts lines 196-201 to pass database.Name instead of the requested name. Update test/integration/turso-api-management.test.ts lines 208-232 to expect the DELETE request for the returned database name.scripts/database-snapshot-lib.ts (1)
229-242: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winCheck abort state before starting the operation.
client.sync()is evaluated beforewaitForOrAbortcallsthrowIfAborted, so an already-aborted migration can still start a source sync.
scripts/database-snapshot-lib.ts#L229-L242: accept an operation thunk and call it only after checkingsignal.throwIfAborted().test/scripts/database-snapshot-safety.test.ts#L125-L167: add a pre-aborted-signal test that assertssyncwas never invoked and temporary files were removed.As per coding guidelines, every bug fix must include a regression test reproducing the original defect.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/database-snapshot-lib.ts` around lines 229 - 242, Update waitForOrAbort in scripts/database-snapshot-lib.ts:229-242 to accept an operation thunk, check signal.throwIfAborted() first, and invoke the thunk only afterward while preserving abort-race cleanup. Add a regression test in test/scripts/database-snapshot-safety.test.ts:125-167 using a pre-aborted signal that verifies sync is never invoked and temporary files are removed.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/scripts/termination-signals.test.ts`:
- Around line 34-46: The termination signal tests should verify per-signal
continuation rather than allowing a loop-wide catch to pass. Update the stubs in
the registration and removal tests to throw only for SIGINT, track calls to the
signal APIs, and assert that SIGTERM is still attempted after SIGINT fails in
both onTerminationSignals and offTerminationSignals.
---
Outside diff comments:
In `@scripts/database-snapshot-lib.ts`:
- Around line 229-242: Update waitForOrAbort in
scripts/database-snapshot-lib.ts:229-242 to accept an operation thunk, check
signal.throwIfAborted() first, and invoke the thunk only afterward while
preserving abort-race cleanup. Add a regression test in
test/scripts/database-snapshot-safety.test.ts:125-167 using a pre-aborted signal
that verifies sync is never invoked and temporary files are removed.
In `@src/shared/turso-api.ts`:
- Around line 196-201: Update the name-mismatch branch in cleanUpFailedCreate
usage within src/shared/turso-api.ts lines 196-201 to pass database.Name instead
of the requested name. Update test/integration/turso-api-management.test.ts
lines 208-232 to expect the DELETE request for the returned database name.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: d11e2610-6436-476d-a79f-ebbd3354f7a0
📒 Files selected for processing (6)
scripts/database-snapshot-lib.tsscripts/turso-migration-lib.tssrc/shared/turso-api.tstest/integration/turso-api-management.test.tstest/scripts/database-snapshot-safety.test.tstest/scripts/termination-signals.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9382f63cd5
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e40231348
ℹ️ 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".
… abortable operations
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/test-utils/turso-migration.ts`:
- Around line 116-119: Update the verifyUploadFile test double in the migration
test utilities to record the provided AbortSignal in the relevant state, then
add a happy-path assertion that runMigrateTursoCli forwards state.deps.signal to
verification. Preserve the existing verification event recording and Promise
resolution behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 01bb09e4-695b-4ab3-83d5-9f9da715e2c6
📒 Files selected for processing (9)
scripts/database-snapshot-lib.tsscripts/turso-migration-file.tsscripts/turso-migration-lib.tsscripts/turso-migration.tssrc/shared/turso-api.tstest/integration/turso-api-management.test.tstest/scripts/termination-signals.test.tstest/scripts/turso-migration.test.tstest/test-utils/turso-migration.ts
Summary
deno task migrate:turso, which asks for the source database, the new Turso name, and any Turso details that are not already in.env.DB_URLandDB_TOKENwhen the migration succeeds, even if temporary-file cleanup then needs operator help.Safety
The task hides entered tokens, streams large files with an exact byte length, validates Turso responses before using them, and keeps temporary files owner-only. The app encryption key is not in the database file, so the task reminds the operator to keep using the source
DB_ENCRYPTION_KEY.Testing
nix develop -c deno task precommitSummary by CodeRabbit
New Features
deno task migrate:turso.DB_URLandDB_TOKENon success.Documentation
TURSO_API_TOKEN,TURSO_ORGANIZATION, andTURSO_GROUPto the environment variable docs, including full migration and cleanup steps.Bug Fixes
Tests