Skip to content

Support TursoDB database imports - #1062

Merged
pedrocarlo merged 6 commits into
mainfrom
codex/support-tursodb-imports
Jul 29, 2026
Merged

Support TursoDB database imports#1062
pedrocarlo merged 6 commits into
mainfrom
codex/support-tursodb-imports

Conversation

@pedrocarlo

Copy link
Copy Markdown
Collaborator

Summary

  • detect rollback, WAL, and MVCC SQLite file formats before import
  • safely checkpoint sidecars and convert compatible uploads to TursoDB format
  • default db import to TursoDB and route file seeds through the upload flow
  • add coverage for file-format detection, sidecar handling, and multipart conversion

Why

TursoDB imports could be routed through an incompatible create path or rejected because the uploaded file format did not match the target database. The import flow now validates and converts supported inputs without silently dropping sidecar data.

Validation

  • go test ./internal/turso passes
  • go test ./internal/cmd currently fails in pre-existing TestGetReservedBytes: expected 0 reserved bytes, got 12

@pedrocarlo
pedrocarlo marked this pull request as ready for review July 28, 2026 17:48
Comment thread internal/cmd/db_create.go Outdated
Comment thread internal/cmd/group_flag.go Outdated
Comment thread internal/cmd/group_flag.go Outdated
Comment thread internal/cmd/group_flag.go Outdated
Comment thread internal/cmd/db_import.go Outdated
Comment thread internal/cmd/group_flag.go Outdated
// sidecars are empty.
func prepareTursoDBFile(file string) error {
output, err := exec.Command("tursodb", "-q", "-m", "list", file,
"PRAGMA journal_mode = mvcc; PRAGMA wal_checkpoint(TRUNCATE); PRAGMA quick_check;").CombinedOutput()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #1012, I added a spinner during quick_check, because for large DBs, it can make appear like the CLI is hanging. With this change, it doesn't look like there's a spinner.

See the runQuickCheck() function.

Comment thread internal/cmd/group_flag.go Outdated
// checkpoint any logical-log entries into the main file, and validate the
// resulting database. Uploading only the main file is safe once all data-bearing
// sidecars are empty.
func prepareTursoDBFile(file string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's weird that the checkpointing/preparing/pre-upload logic is in a file called group_flag.go 🤔

Comment thread internal/cmd/group_flag.go Outdated
Comment thread internal/cmd/group_flag.go Outdated
if cipher != "" {
return nil, errors.New("remote encryption is not supported when importing tursodb (MVCC) format files")
}
case fileFormatNotSQLite:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileFormatUnknown is not handled

Comment thread internal/cmd/group_flag.go Outdated
if err := checkpointWALBeforeUpload(file); err != nil {
return nil, err
}
if err := sqliteFileIntegrityChecks(file, cipher); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function contains some nice code (a good error message if the user uploads a dump, spinner on quick_check, max size check, page size, etc.) that isn't replicated in the Turso code. Maybe reuse this function with turso instead of sqlite?

Comment thread internal/cmd/group_flag.go Outdated
}
}

fileInfo, err := os.Stat(file)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is now performed twice for WAL-mode databases (other one is in sqliteFileIntegrityChecks).

Comment thread internal/cmd/group_flag.go Outdated
func checkTursoDBAvailable() error {
_, err := exec.LookPath("tursodb")
if errors.Is(err, exec.ErrNotFound) {
return errors.New("could not find tursodb on your system. Please install it to import into a TursoDB database")

@LeMikaelF LeMikaelF Jul 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a sub-par first experience for a new user looking to import their DB into the cloud, because they'll need to install turso, then get an error, and figure out how to download tursodb.

Could we give them instructions on installing tursodb?

I wonder if there's a way we could avoid this. It doesn't make sense for a user to have to install 2 CLI's.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use turso-go. I did this because we also require the user to have sqlite3 installed. Don't know if this introduces any issues for building the cli.

pedrocarlo and others added 2 commits July 29, 2026 13:04
Co-authored-by: Mikaël Francoeur <mikael.francoeur@hotmail.com>
@pedrocarlo
pedrocarlo force-pushed the codex/support-tursodb-imports branch from ec3d239 to 1b8cb41 Compare July 29, 2026 16:38
Comment thread internal/cmd/db_import_file.go Outdated

type databaseFileChecker struct {
name string
binary string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this type is now weird, because the binary field either has value sqlite3 or ""

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i've seen it and will adjust it, Im first just trying to the run code locally first to confirm it works, then will move to an interface of functions probably

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe just an int to identify

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok changed it now

@pedrocarlo
pedrocarlo force-pushed the codex/support-tursodb-imports branch from b4721e9 to 3e94c78 Compare July 29, 2026 20:56
@pedrocarlo
pedrocarlo merged commit b65778d into main Jul 29, 2026
1 check passed
@pedrocarlo
pedrocarlo deleted the codex/support-tursodb-imports branch July 29, 2026 21:28
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.

2 participants