# CLI databases Manage the current Site database and keep schema changes in numbered SQL files under the project-root `migrations/` directory. ## Create a database ```sh interfold db create --site ``` ## Query a database Forward generic D1 SQL with a write-authorized API key. Queries can read or change data and schema, so use placeholders for values and review writes carefully: ```sh interfold db query --site 'SELECT id, name FROM users WHERE active = ?' --params '[true]' interfold db query --site 'UPDATE users SET active = ? WHERE id = ?' --params '[false, 42]' ``` The command prints the D1-style response envelope. It accepts one SQL string and an optional JSON parameter array; D1 evaluates SQL errors. This is a write-capability command even for a `SELECT` statement. ## Create and inspect migrations ```sh interfold db migrations create create_users interfold db migrations list --site ``` `list` returns successful cloud migration receipts without reading local migration files. `apply` compares the ordered local migration prefix with provider history before applying pending files. When an API operation fails, the CLI reads the REST error envelope and carries documented recovery metadata from `error.details` into its structured command error. It keeps REST transport details separate from its own JSON stderr output. ## Apply migrations ```sh interfold db migrations apply --site --confirm ``` Always run `list` immediately before `apply`. An interrupted request can be recovered by listing again; do not guess whether the provider committed a migration. ## Delete permanently Deletion is a two-step operation: ```sh interfold db delete --site interfold db delete --site --confirm DELETE-XXXXXXXX ``` The first command creates a short-lived challenge and changes nothing. Export important data before confirming deletion. See [Databases](/databases) for direct-query behavior, runtime queries, and migration-file rules.