TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/launchbadge/sqlx/llms.txt
Use this file to discover all available pages before exploring further.
sqlx database command group (alias sqlx db) manages the lifecycle of the database itself. Use it to create a fresh database before running your first migration, drop a database to start over, perform a combined drop-and-recreate, or set up a brand-new database and apply all pending migrations in one step.
sqlx database create
Creates the database named in yourDATABASE_URL if it does not already exist. The command is idempotent — running it against an existing database does nothing.
CREATEDB privilege.
SQLite databases are created in Write-Ahead Log (WAL) mode by default. If your application sets
journal_mode to something other than WAL on SqliteConnectOptions, it will need to take the file out of WAL mode on its first connection. To disable WAL mode at creation time, pass --sqlite-create-db-wal false.sqlx database drop
Drops the database named in yourDATABASE_URL. By default, the command prompts for confirmation before proceeding.
-y to skip the confirmation prompt, which is useful in scripts and CI pipelines:
--force (-f) to terminate existing connections and force the drop:
sqlx database setup
Creates the database and immediately runs all pending migrations. This is equivalent to runningsqlx database create followed by sqlx migrate run, and is useful for bootstrapping a new environment in a single command.
sqlx database reset
Drops the database, re-creates it, and runs all pending migrations. Use this during development to restore a clean state.drop, pass -y to skip the confirmation prompt and --force (PostgreSQL only) to terminate active connections:
Common flags
Allsqlx database subcommands accept the following flags:
| Flag | Short | Description |
|---|---|---|
--database-url <URL> | -D | Override DATABASE_URL for this invocation |
--connect-timeout <SECONDS> | Maximum seconds to wait for a connection (default: 10) | |
--no-dotenv | Do not load .env files automatically | |
--config <PATH> | Path to sqlx.toml (defaults to sqlx.toml in the current directory) |
drop and reset subcommands also accept:
| Flag | Short | Description |
|---|---|---|
-y / --yes | -y | Skip the confirmation prompt |
--force | -f | PostgreSQL only: force-drop by terminating active connections |