INTEGRITY Cloudflare Docs

D1

Interact with D1 databases service using Wrangler.

d1 create

Creates a new D1 database, and provides the binding and UUID that you will put in your config file

This command acts on remote D1 Databases.

npx wrangler d1 create [NAME]

Global flags

d1 info

Get information about a D1 database, including the current database size and state

This command acts on remote D1 Databases.

npx wrangler d1 info [NAME]

Global flags

d1 list

List all D1 databases in your account

This command acts on remote D1 Databases.

npx wrangler d1 list

Global flags

d1 delete

Delete a D1 database

This command acts on remote D1 Databases.

npx wrangler d1 delete [NAME]

Global flags

d1 execute

Execute a command or SQL file

You must provide either --command or --file for this command to run successfully.

npx wrangler d1 execute [DATABASE]

Global flags

d1 export

Export the contents or schema of your database as a .sql file

npx wrangler d1 export [NAME]

Global flags

d1 time-travel info

Retrieve information about a database at a specific point-in-time using Time Travel

This command acts on remote D1 Databases.

For more information about Time Travel, see https://developers.cloudflare.com/d1/reference/time-travel/

npx wrangler d1 time-travel info [DATABASE]

Global flags

d1 time-travel restore

Restore a database back to a specific point-in-time

This command acts on remote D1 Databases.

For more information about Time Travel, see https://developers.cloudflare.com/d1/reference/time-travel/

npx wrangler d1 time-travel restore [DATABASE]

Global flags

d1 migrations create

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.

npx wrangler d1 migrations create [DATABASE] [MESSAGE]

Global flags

d1 migrations list

View a list of unapplied migration files

npx wrangler d1 migrations list [DATABASE]

Global flags

d1 migrations apply

Apply any unapplied D1 migrations

This command will prompt you to confirm the migrations you are about to apply. Confirm that you would like to proceed. After applying, 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.

npx wrangler d1 migrations apply [DATABASE]

Global flags

d1 insights


Experimental

Get information about the queries run on a D1 database

This command acts on remote D1 Databases.

npx wrangler d1 insights [NAME]

Global flags