Appearance
CLI installation and usage
The ts CLI signs you into TerraScale and manages projects, databases, backups, SQL and project API keys as your user. You need a TerraScale account.
See the automation and JSON reference for machine output contracts.
Install
macOS and Linux, Intel/AMD 64-bit (amd64) and ARM64 (arm64):
sh
curl -fsSL https://terrascale.tech/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
ts --versionThe installer downloads the latest sdk/go/v0.0.X release from the releases page, checks its SHA-256 against checksums.txt, and installs ts to ~/.local/bin without sudo. sh install.sh 0.0.2 installs a specific release.
With Homebrew on macOS or Linux:
sh
brew install terrascale/tap/tsOn Windows, download ts_windows_amd64.zip or ts_windows_arm64.zip from the releases page, verify it against checksums.txt (Get-FileHash .\ts_windows_amd64.zip -Algorithm SHA256), and extract ts.exe into a user-owned directory on PATH.
With Go 1.25 or later on any platform:
sh
go install terrascale.tech/sdk/cmd/ts@latestRelease builds print ts 0.0.X; go install and source builds print ts dev. ts help (or ts --help) lists every command. Options accept one or two dashes (-json or --json) and go before or after the command and its operands. Invalid arguments exit with status 2 and other failures with status 1.
Upgrade
Use the same installation method to upgrade, then check the installed binary:
sh
# Installer: rerun it to replace the binary with the latest release.
curl -fsSL https://terrascale.tech/install.sh | sh
# Homebrew:
brew update && brew upgrade ts
# Go:
go install terrascale.tech/sdk/cmd/ts@latest
# After your chosen method:
ts --versionShell completion
Run the block for your shell. All files go into user-owned directories.
bash
mkdir -p ~/.local/share/bash-completion/completions
ts completion bash > ~/.local/share/bash-completion/completions/ts
source ~/.local/share/bash-completion/completions/tszsh
mkdir -p ~/.local/share/terrascale
ts completion zsh > ~/.local/share/terrascale/completion.zsh
source ~/.local/share/terrascale/completion.zshAdd the zsh source line to ~/.zshrc to load it in new sessions.
fish
mkdir -p ~/.config/fish/completions
ts completion fish > ~/.config/fish/completions/ts.fish
source ~/.config/fish/completions/ts.fishStart from the CLI
After installing, create your own project and database:
sh
ts auth login
ts projects create my-project
ts -project my-project db create exampleOne command to a working setup
ts init takes a signed-in developer from nothing to a working connection. It reuses the selected project's database <db> (or creates it with the project's default placement), creates one API key scoped to that database with sql:read and sql:write, writes a .env in the current directory (mode 0600, never overwriting an existing file) and prints the install line and a first query snippet for the SDK it detects in the directory:
sh
ts init # uses main, or the project's only database
ts init example # reuse or create a named databasePass -lang <js|go|python|dotnet|rust> to pick the snippet yourself, and -yes to create the database and key without the one confirmation. The key's secret is printed once and written to .env as TERRASCALE_API_KEY, next to TERRASCALE_PROJECT_ID, TERRASCALE_DATABASE_NAME and TERRASCALE_REGION, one region of the database's set; only the .NET snippet reads the region.
Sign in
sh
ts auth loginOpen the URL printed by the CLI in your browser and confirm the displayed code. The command waits until sign-in completes and prints Signed in.. Commands use your project permissions. The CLI stores your sign-in in your user config directory (~/.config/terrascale/cli.json on Linux, ~/Library/Application Support/terrascale/cli.json on macOS, %AppData%\terrascale\cli.json on Windows), readable only by you (mode 0600), and refreshes it when needed.
sh
ts whoami # the signed-in account
ts projects # every project you can reach, with its ID and your roleIf you have exactly one project, the CLI selects it automatically. With multiple projects, put -project before the command and use a project name or ID:
sh
ts -project my-project db listUse the project ID from ts projects if names are ambiguous. If the CLI reports no project, create one:
sh
ts projects create my-project
ts -org my-org projects create other-project # pick the organizationprojects create uses your only organization, or creates an organization of the same name when you have none.
In CI, set TERRASCALE_API_KEY to an API key instead of running ts auth login. Database commands then act as that key in its project. Store the key in your CI secret store. See CI.
Manage databases
sh
ts db list
ts db create example
ts db info exampledb list lists databases. db info prints one database's metadata as JSON, including its immutable ULID. db export <db> downloads a database as a SQL dump to stdout; -o file writes it atomically, leaving no file if the export is interrupted, and -force overwrites an existing file. db import <db> <file|-> loads such a dump, or any SQLite-dialect .sql file, back into a database in batches; - reads stdin. The import is not atomic: each batch commits on its own; on failure the CLI prints the first failed statement's number and -from <n> resumes past the first n-1 statements. db rename <db> <new-name> (the long form is ts databases rename) renames a database by name or ULID:
sh
ts db rename example example-prodBranches
Two forms exist. db branch <source> <db> copies an existing database into a new one and keeps the copy forever:
sh
ts db branch example example-previewdb branch create <name> --from <db> [--ttl 7d] creates a short-lived branch that expires on its own (default lifetime 7 days):
sh
ts db branch create preview --from example --ttl 1d
ts db branch list
ts db branch delete previewdb branch url <name> is the easiest way to get a connection URL for the Postgres wire endpoint, which serves SQLite-dialect SQL: it issues a scoped secret URL for that one database, valid for at most 7 days. It requires an API key, so run it with TERRASCALE_API_KEY set. db url <db> does the same for a regular database:
sh
TERRASCALE_API_KEY=... ts db branch url preview
TERRASCALE_API_KEY=... ts db url examplePlacement
sh
ts db create example -regions gru,fra
ts db placement example -regions sjc,fra
ts db regions exampledb create takes -regions, a comma-separated list of one to nine region ids. Every region of the set is an equal peer that accepts reads and writes; there is no home region to pick. -all-regions places the database in every serving region, including regions added later. db placement <name> -regions … changes the set later with the same -regions list, or with -all-regions. When an added region has not caught up yet, the regions you added stay added and ts db placement <name> -regions … exits with a message asking you to run the same command again. db regions <db> prints each region's health, replication lag in milliseconds and applied bookmark.
Database deletion asks you to type the database name in a terminal before it deletes data. For an unattended script, explicitly consent with ts -project my-project -yes db delete example.
Backups
sh
ts backup list example
ts backup create examplebackup list shows each backup's ID, status, trigger, size and creation time; backup create takes a backup on demand.
Policy
sh
ts backup policy example
ts backup policy-set example "0 3 * * *" 14backup policy reads the snapshot schedule and retention. backup policy-set <db> <cron|none> <days> sets a five-field UTC cron schedule and a retention from 1 day up to the plan's backup retention (1 day on Free, 3 on Starter, 7 on Pro, 14 on Team, 30 on Enterprise); none stops scheduled backups.
Destination
sh
ts backup destination get
cat credentials.json | ts -yes backup destination set
ts backup destination deleteThe project backup bucket is where customer-owned backups are shipped. set reads the credential JSON from stdin and requires -yes; delete types the project ID before removing the destination.
Restore
sh
ts backup window example
ts backup plan example 2025-01-01T00:00:00Z
ts backup restore example 01JZ8Q5B7C9D1E3F5G7H9J1K3M example-restored
ts backup restore-at example 2025-01-01T00:00:00Z example-restored
ts -yes backup rewind example 2025-01-01T00:00:00Zbackup window shows the proven restore interval for the platform (platform) or your own bucket (customer). backup plan <db> <time> [platform|customer] previews the restore metadata for an RFC3339 instant before restoring. backup restore <db> <backup id> <new db> restores one backup into a new database. backup restore-at <db> <time> <new db> [platform|customer] restores the database state at an RFC3339 instant into a new database (default platform). backup rewind <db> <time> [platform|customer] restores the database in place to an instant; later changes are lost, so it requires -yes for automation.
Organizations, projects and context
sh
ts orgs
ts orgs create acme
ts orgs info acme
ts orgs rename acme acme-corp
ts orgs delete acmeorgs lists every accessible organization. orgs create makes a new one; orgs info inspects one; orgs rename needs admin and orgs delete needs owner, an empty organization and a fresh sign-in confirmation: after the typed ID, or -yes, which skips only that, it prints the hosted confirmation URL and waits for you to approve it, as keys rotate does.
sh
ts projects info my-project
ts projects rename my-project prod
ts -yes projects delete 01JD2V5QANWG7Z4KQVKJFM8RHTprojects info inspects a project (add -org <name> to restrict lookup); projects rename needs admin; projects delete removes an identity project after all its databases are gone and requires typing the project ID or an explicit -yes.
sh
ts context show
ts context set acme prod example
ts context clearcontext saves verified organization, project and database selectors so you can stop repeating -project; context set takes <org> <project> [<database>], and other commands accept @ as the saved database. ts billing prints the dashboard billing URL without signing in.
Usage
sh
ts usage # the project and each database, as JSON
ts usage example # one databaseusage prints storage and hourly reads and writes for the last day.
Run SQL
SQL is described in SQL. Run one statement with ts sql <db> <statement>; rows print as JSON lines, writes print N rows affected:
sh
ts sql example "CREATE TABLE people (id TEXT PRIMARY KEY, name TEXT)"
ts sql example "INSERT INTO people (id, name) VALUES ('a1', 'ada'), ('a2', 'bob')"
ts sql example "SELECT id, name FROM people ORDER BY id"With several projects, put -project <name> before sql. For a multiline SQL shell with session history, use ts shell <db> (.run submits; each engine call runs exactly one statement).
Consistency and bookmarks
ts sql and ts shell take two options, after the database name:
| Option | Effect |
|---|---|
-consistency fast|strong | fast commits in the region you reach and replicates afterwards; strong commits on two of three regions after checking the rows the statement read and wrote. Without it the database's default applies (fast unless set otherwise). |
-bookmark <bookmark> | Waits until the region you reach has applied the writes this bookmark covers, then runs: read-your-writes from another machine or region. |
After each statement, ts sql prints bookmark <value> on stderr (with -json, the result's bookmark field). Pass it to a later command:
sh
ts sql example "UPDATE accounts SET balance = balance - 25 WHERE id = 'acct_1'" -consistency strong
# bookmark AQMDZnJhBANncnUKA3NqYwc
ts sql example "SELECT balance FROM accounts WHERE id = 'acct_1'" -bookmark AQMDZnJhBANncnUKA3NqYwc
ts shell example -consistency strongSchema changes and writes to tables with a secondary UNIQUE constraint always run strong. See replication and consistency.
Functions
sh
ts functions deploy example handler.js
ts functions list example
ts functions invoke example handler -data '{"id":"a1"}'
ts functions logs example handler
ts functions delete example handlerfunctions deploy deploys or replaces a JavaScript function from a file or a directory (a directory deploys its index.js); -name <name> overrides the name and -cron <expr> schedules it. The file is a plain script, not an ES module, that defines function handler(event). functions invoke runs one function (-data <json> sends a body, - reads stdin), functions logs prints recent invocations as JSON lines newest first (-limit 1..100), and functions delete removes a function and its logs.
Schema migrations
sh
ts migrate new "add orders" # add the next migrations/NNNN_<name>.sql
ts migrate up app # apply pending migrations, each in one transaction
ts migrate status app # list each migration and whether it is applied
ts migrate diff app-orders # print the schema changes against the branched-from database
ts sql app 'SELECT * FROM orders LIMIT 10' # run one SQL statementSee Schema migrations for the file format, history and workflow.
Schema files
sh
ts schema pull example
ts schema diff example schema.sql
ts schema apply example schema.sqlschema pull writes schema.sql from the database, schema diff prints the DDL needed to reach the file, and schema apply applies it atomically; -dry-run previews and -allow-drop consents to DROP operations.
API keys
sh
ts db info example # the "id" field is the database's canonical ULID
ts keys create backend 01JD2V5QANWG7Z4KQVKJFM8RHT
ts keys list
ts keys rotate 01JZ8Q5B7C9D1E3F5G7H9J1K3M 1h
ts keys revoke 01JZ8Q5B7C9D1E3F5G7H9J1K3Mkeys create takes the database's immutable ULID (from ts db info <name>), not its name. It makes a project key with read and write access, restricted to that database. It prints the key once on standard output; store it immediately in your secret manager. Use the key with an SDK's API key token exchange, as getting started shows. keys rotate <id> <grace> rotates a key once; the grace is a required whole-second duration from 0s to 24h during which the previous secret stays valid, and the new secret appears once on stdout.
Rotating a key needs a fresh sign-in confirmation with your password or an email code, plus two-factor authentication when enrolled. The command prints the hosted confirmation URL and waits for you to approve it in a browser; after approval the one-time secret is printed in the terminal. Ctrl+C cancels the wait; an unconfirmed request expires after five minutes and the command exits with 403 step_up_required. keys create, keys list and keys revoke work from the CLI without a sign-in confirmation.
Key lifetime and allowed networks
Keys default to no expiry and read/write scopes. Prefer an expiry and a database restriction. Key-creation options go before or after the command:
sh
ts -expires 30d -allow-cidr 203.0.113.0/24 keys create app 01JD2V5QANWG7Z4KQVKJFM8RHTReplace the documentation network above with your application's real egress CIDR. Expiry accepts 30d, 90d, 365d or never; CIDRs are comma-separated. Treat the one-time key output as a secret; write it only to a private file or secret store.
Sign out
sh
ts auth logoutThis revokes the stored refresh token and removes the local sign-in after a successful revocation. Run ts auth login again if a command reports an expired sign-in.