# CLI databases Manage private account-owned SQLite databases by stable ID, or use the existing site convenience commands. Ownership is immutable; attachment does not change IDs, data, migration receipts, or export history. ## Create and list account databases ```sh interfold db create --unattached --account --idempotency-key interfold db list --account --limit 25 --offset 0 interfold db get --database ``` Account and credentials follow the usual flag → environment → nearest project link → default selection. `--database` chooses a resource directly and ignores an inherited site; it cannot be combined with `--site` or `--subdomain`. Account authorization still applies to every stable-ID request. Account creation requires `--idempotency-key`: 1–255 printable ASCII characters without spaces, for example a UUID. Save the key together with the selected account and target before running creation. The CLI does not generate or persist keys. Retry the same `create` command with the same key and account to recover incomplete provisioning; there is no separate provision or resource-update command. A new key allocates a new database. Creation replay returns its original resource even after detach. `DATABASE_CREATION_DELETED` means that resource was deleted; intentionally create a replacement with a fresh key. Reusing a key with a different site or switching between account and site creation returns `DATABASE_CREATION_REQUEST_MISMATCH`. Recovery without the original key is deferred; do not guess a fresh key to retry an uncertain creation. Creation failures include `creationKey` and preserve a server-provided `databaseId` when available. Provisioning recovery commands pin the resolved account, target, and original key. If an unscoped API key leaves the account unknown, the CLI omits the unsafe headerless command; repeat your original command with the retained key and credential. Site creation remains supported: ```sh interfold db create --site --idempotency-key interfold db create --site ``` Headerless site creation uses the server's permanent legacy creation mapping. After deletion, an intentional replacement requires an explicit fresh key. Explicit keys are account-scoped across both creation modes: keep each key paired with its original account and target. ## Query a database ```sh interfold db query 'SELECT id, name FROM users WHERE active = ?' --database --params '[true]' interfold db query 'UPDATE users SET active = ? WHERE id = ?' --site --params '[false, 42]' ``` The command accepts one SQL string and an optional JSON array of strings, numbers, booleans, or null. It prints the D1-style response envelope. Query requires write permission even for `SELECT`; review writes carefully. ## Create and inspect migrations Keep numbered SQL files such as `migrations/0001_create_users.sql` at the project root. Existing file conventions and provider receipt checks remain unchanged. ```sh interfold db migrations create create_users interfold db migrations list --database interfold db migrations get 0001_create_users.sql --database ``` `list` and `get` read successful cloud receipts without reading local SQL. Applied names and checksums are immutable: add a forward migration instead of editing an applied file. ## Apply migrations ```sh interfold db migrations apply --database --confirm interfold db migrations apply ./migrations/0001_create_users.sql --database --confirm ``` With no filename, `apply` resolves the project-root `migrations/` directory, submits the ordered local prefix for provider-history verification, and reports its absolute directory. With a filename, it sends that file's basename and exact SQL bytes to the single-migration route. Relative filenames resolve from `--cwd` or the working directory. Both require explicit `--confirm` and preserve receipt integrity checks. `--site` and `--subdomain` remain available for migration and query commands. Run `list` immediately before applying. After an interrupted apply, inspect receipts and any reported lease expiry before retrying the same files. ## Exports ```sh interfold db exports list --database --limit 25 --offset 0 interfold db exports create --database interfold db exports reconcile --database ``` Create returns an export resource. Reconcile that ID until `status: COMPLETE` provides an expiring download URL; each reconcile call is explicit. These commands also accept site convenience targets. Creating and reconciling exports require write permission; account-member sessions require account admin access for exports. ## Explicit attachment ```sh interfold db attach --database --site interfold db detach --database --site ``` Both IDs are required explicitly, and the API enforces same-account ownership. Attachment changes preserve database identity and history. Unattached databases have no `ctx.db` runtime access. Production attachment changes are enabled after the runtime upgrade and audit. `DATABASE_ATTACHMENTS_DISABLED` means the current deployment has placed changes on hold; CLI commands do not activate the flag. Site creation remains the convenience provisioning path. ## Delete permanently Attached databases reject deletion through either surface with `DATABASE_ATTACHED`. Detach first, then request a fresh challenge by stable ID: ```sh interfold db delete --database interfold db delete --database --confirm DELETE-XXXXXXXX ``` The first command creates a short-lived, database-bound challenge and changes no database data. Only the second permanently deletes it. Export important data first. Legacy `delete --site ` remains supported but obeys the same attachment guard. The root challenge route uses `deletion_challenges`. ## Failures and recovery Structured errors preserve safe REST codes, retryability, unknown-outcome state, resource IDs, migration blockers and names, lease expiry, and recovery actions. The CLI makes no automatic mutation retries. A lost mutation response is reported as `DATABASE_REQUEST_OUTCOME_UNKNOWN`; failures before dispatch retain actionable `REQUEST_INVALID` or `REQUEST_ENCODING_FAILED` codes. Inspect the resource, receipts, or exports before repeating a write. For creation recovery, always reuse the original key, account, and target. `DATABASE_CREATE_OUTCOME_UNKNOWN` never warrants a fresh-key allocation; repeated same-key creation invokes the server's provisioning recovery. See [Databases](/databases) for runtime behavior and receipt integrity rules, or return to the [dashboard](https://app.interfold.dev).