Skip to main content

Documentation 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.

The 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 your DATABASE_URL if it does not already exist. The command is idempotent — running it against an existing database does nothing.
sqlx database create
For SQLite, the database file is created at the path specified in the URL. For PostgreSQL and MySQL, the server must be reachable and the connecting user must have the 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 your DATABASE_URL. By default, the command prompts for confirmation before proceeding.
sqlx database drop
Use -y to skip the confirmation prompt, which is useful in scripts and CI pipelines:
sqlx database drop -y
For PostgreSQL, pass --force (-f) to terminate existing connections and force the drop:
sqlx database drop -y --force
Dropping a database is irreversible. All data, schema objects, and migration history are permanently deleted.

sqlx database setup

Creates the database and immediately runs all pending migrations. This is equivalent to running sqlx database create followed by sqlx migrate run, and is useful for bootstrapping a new environment in a single command.
sqlx database setup

sqlx database reset

Drops the database, re-creates it, and runs all pending migrations. Use this during development to restore a clean state.
sqlx database reset
As with drop, pass -y to skip the confirmation prompt and --force (PostgreSQL only) to terminate active connections:
sqlx database reset -y --force

Common flags

All sqlx database subcommands accept the following flags:
FlagShortDescription
--database-url <URL>-DOverride DATABASE_URL for this invocation
--connect-timeout <SECONDS>Maximum seconds to wait for a connection (default: 10)
--no-dotenvDo not load .env files automatically
--config <PATH>Path to sqlx.toml (defaults to sqlx.toml in the current directory)
The drop and reset subcommands also accept:
FlagShortDescription
-y / --yes-ySkip the confirmation prompt
--force-fPostgreSQL only: force-drop by terminating active connections

Connection URL formats

DATABASE_URL=postgres://user:password@localhost/dbname

Build docs developers (and LLMs) love