Skip to content
Latchkey

turso db create and db shell: Turso from CI

turso db create provisions a libSQL database on Turso, and turso db shell runs SQL against a database from the command line.

Turso is a libSQL/SQLite-based edge database. The CLI provisions databases and runs SQL, both handy for CI test setup and migrations.

What it does

turso db create NAME provisions a new database, optionally near a --location. turso db shell NAME opens a SQL shell or runs a single statement passed as an argument. turso db tokens create NAME mints a database auth token, and turso db show NAME prints connection details.

Common usage

Terminal
# non-interactive auth with an API token
export TURSO_API_TOKEN=xxx
turso db create test-db --location iad
# run one statement (non-interactive) by passing it as an argument
turso db shell test-db "SELECT count(*) FROM users;"
turso db tokens create test-db

Options

Command / flagWhat it does
db create <name>Provision a new database
--location <code>Primary region for the database
db shell <name> [sql]Open a SQL shell or run one statement
db tokens create <name>Mint a database auth token
db show <name>Print connection URL and details
TURSO_API_TOKENPlatform API token for CI auth

In CI

Set TURSO_API_TOKEN (created with turso auth api-tokens mint) so the CLI authenticates without the interactive turso auth login browser flow. Pass the SQL as an argument to turso db shell so it runs and exits instead of opening an interactive prompt that would hang the job.

Common errors in CI

"Error: not logged in, please login with turso auth login" means TURSO_API_TOKEN is unset or invalid. "database <name> already exists" on create means a leftover from a prior run; use a unique name or drop it first. A hanging step is db shell with no SQL argument waiting for interactive input.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →