Wrangler commands
D1 Wrangler commands use REST APIs to interact with the control plane. This page lists the Wrangler commands for D1.
Creates a new D1 database, and provides the binding and UUID that you will put in your wrangler.toml
file.
DATABASE_NAME
string required- The name of the new D1 database.
--location
string optional- Provide an optional location hint for your database leader.
- Available options include
weur
(Western Europe),eeur
(Eastern Europe),apac
(Asia Pacific),oc
(Oceania),wnam
(Western North America), andenam
(Eastern North America).
Get information about a D1 database, including the current database size and state.
DATABASE_NAME
string required- The name of the D1 database to get information about.
--json
boolean optional- Return output as JSON rather than a table.
List all D1 databases in your account.
--json
boolean optional- Return output as JSON rather than a table.
Delete a D1 database.
DATABASE_NAME
string required- The name of the D1 database to delete.
-y, --skip-confirmation
boolean optional- Skip deletion confirmation prompt.
Execute a query on a D1 database.
DATABASE_NAME
string required- The name of the D1 database to execute a query on.
--command
string optional- The SQL query you wish to execute.
--file
string optional- Path to the SQL file you wish to execute.
-y, --yes
boolean optional- Answer
yes
to any prompts.
- Answer
--local
boolean (default: true) optional- Execute commands/files against a local database for use with wrangler dev.
--remote
boolean (default: false) optional- Execute commands/files against a remote D1 database for use with wrangler dev --remote.
--persist-to
string optional- Specify directory to use for local persistence (for use in combination with
--local
).
- Specify directory to use for local persistence (for use in combination with
--json
boolean optional- Return output as JSON rather than a table.
--preview
boolean optional- Execute commands/files against a preview D1 database (as defined by
preview_database_id
in Wrangler.toml).
- Execute commands/files against a preview D1 database (as defined by
--batch-size
number optional- Number of queries to send in a single batch.
Export a D1 database or table's schema and/or content to a .sql
file.
DATABASE_NAME
string required- The name of the D1 database to export.
--remote
boolean (default: false) optional- Execute commands/files against a remote D1 database for use with wrangler dev --remote.
--output
string optional- Path to the SQL file for your export.
--table
string optional- The name of the table within a D1 database to export.
--no-data
boolean (default: false) optional- Controls whether export SQL file contains database data. Note that
--no-data=true
is not recommended due to a known wrangler limitation that intreprets the value as false.
- Controls whether export SQL file contains database data. Note that
--no-schema
boolean (default: false) optional- Controls whether export SQL file contains database schema. Note that
--no-schema=true
is not recommended due to a known wrangler limitation that intreprets the value as false.
- Controls whether export SQL file contains database schema. Note that
Restore a database to a specific point-in-time using Time Travel.
DATABASE_NAME
string required- The name of the D1 database to execute a query on.
--bookmark
string optional- A D1 bookmark representing the state of a database at a specific point in time.
--timestamp
string optional- A UNIX timestamp or JavaScript date-time
string
within the last 30 days.
- A UNIX timestamp or JavaScript date-time
--json
boolean optional- Return output as JSON rather than a table.
Inspect the current state of a database for a specific point-in-time using Time Travel.
DATABASE_NAME
string required- The name of the D1 database to execute a query on.
--timestamp
string optional- A UNIX timestamp or JavaScript date-time
string
within the last 30 days.
- A UNIX timestamp or JavaScript date-time
--json
bboolean optional- Return output as JSON rather than a table.
Initiate a D1 backup.
DATABASE_NAME
string required- The name of the D1 database to backup.
List all available backups.
DATABASE_NAME
string required- The name of the D1 database to list the backups of.
Restore a backup into a D1 database.
DATABASE_NAME
string required- The name of the D1 database to restore the backup into.
BACKUP_ID
string required- The ID of the backup you wish to restore.
Download existing data to your local machine.
DATABASE_NAME
string required- The name of the D1 database you wish to download the backup of.
BACKUP_ID
string required- The ID of the backup you wish to download.
--output
string optional- The
.sqlite3
file to write to (defaults to'<DB_NAME>.<SHORT_BACKUP_ID>.sqlite3'
).
- The
Create a new migration.
This will generate a new versioned file inside the migrations
folder. Name your migration file as a description of your change. This will make it easier for you to find your migration in the migrations
folder. An example filename looks like:
0000_create_user_table.sql
The filename will include a version number and the migration name you specify below.
DATABASE_NAME
string required- The name of the D1 database you wish to create a migration for.
MIGRATION_NAME
string required- A descriptive name for the migration you wish to create.
View a list of unapplied migration files.
DATABASE_NAME
string required- The name of the D1 database you wish to list unapplied migrations for.
--local
boolean optional- Show the list of unapplied migration files on your locally persisted D1 database.
--remote
boolean (default: false) optional- Show the list of unapplied migration files on your remote D1 database.
--persist-to
string optional- Specify directory to use for local persistence (for use in combination with
--local
).
- Specify directory to use for local persistence (for use in combination with
--preview
boolean optional- Show the list of unapplied migration files on your preview D1 database (as defined by
preview_database_id
inwrangler.toml
).
- Show the list of unapplied migration files on your preview D1 database (as defined by
Apply any unapplied migrations.
This command will prompt you to confirm the migrations you are about to apply. Confirm that you would like to proceed. After, a backup will be captured.
The progress of each migration will be printed in the console.
When running the apply command in a CI/CD environment or another non-interactive command line, the confirmation step will be skipped, but the backup will still be captured.
If applying a migration results in an error, this migration will be rolled back, and the previous successful migration will remain applied.
DATABASE_NAME
string required- The name of the D1 database you wish to apply your migrations on.
--env
string optional- Specify which environment configuration to use for D1 binding
--local
boolean (default: true) optional- Execute any unapplied migrations on your locally persisted D1 database.
--remote
boolean (default: false) optional- Execute any unapplied migrations on your remote D1 database.
--persist-to
string optional- Specify directory to use for local persistence (for use in combination with
--local
).
- Specify directory to use for local persistence (for use in combination with
--preview
boolean optional- Execute any unapplied migrations on your preview D1 database (as defined by
preview_database_id
inwrangler.toml
).
- Execute any unapplied migrations on your preview D1 database (as defined by
--batch-size
number optional- Number of queries to send in a single batch.
The following global flags work on every command:
--help
boolean- Show help.
--version
boolean- Show version number.
--config
string (not supported by Pages)- Path to
.toml
configuration file.
- Path to