|
2 | 2 | {} |
3 | 3 | --- |
4 | 4 |
|
5 | | -import { Render, AnchorHeading, Type, MetaInfo } from "~/components"; |
| 5 | +import { WranglerNamespace } from "~/components"; |
6 | 6 |
|
7 | | -<AnchorHeading title="`create`" slug="d1-create" depth={3} /> |
8 | | - |
9 | | -Creates a new D1 database, and provides the binding and UUID that you will put in your Wrangler file. |
10 | | - |
11 | | -```txt |
12 | | -wrangler d1 create <DATABASE_NAME> [OPTIONS] |
13 | | -``` |
14 | | - |
15 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
16 | | - - The name of the new D1 database. |
17 | | -- `--location` <Type text="string" /> <MetaInfo text="optional" /> |
18 | | - - Provide an optional [location hint](/d1/configuration/data-location/) for your database leader. |
19 | | - - Available options include `weur` (Western Europe), `eeur` (Eastern Europe), `apac` (Asia Pacific), `oc` (Oceania), `wnam` (Western North America), and `enam` (Eastern North America). |
20 | | - |
21 | | -<AnchorHeading title="`info`" slug="d1-info" depth={3} /> |
22 | | - |
23 | | -Get information about a D1 database, including the current database size and state. |
24 | | - |
25 | | -```txt |
26 | | -wrangler d1 info <DATABASE_NAME> [OPTIONS] |
27 | | -``` |
28 | | - |
29 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
30 | | - - The name of the D1 database to get information about. |
31 | | -- `--json` <Type text="boolean" /> <MetaInfo text="optional" /> |
32 | | - - Return output as JSON rather than a table. |
33 | | - |
34 | | -<AnchorHeading title="`list`" slug="d1-list" depth={3} /> |
35 | | - |
36 | | -List all D1 databases in your account. |
37 | | - |
38 | | -```txt |
39 | | -wrangler d1 list [OPTIONS] |
40 | | -``` |
41 | | - |
42 | | -- `--json` <Type text="boolean" /> <MetaInfo text="optional" /> |
43 | | - - Return output as JSON rather than a table. |
44 | | - |
45 | | -<AnchorHeading title="`delete`" slug="d1-delete" depth={3} /> |
46 | | - |
47 | | -Delete a D1 database. |
48 | | - |
49 | | -```txt |
50 | | -wrangler d1 delete <DATABASE_NAME> [OPTIONS] |
51 | | -``` |
52 | | - |
53 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
54 | | - - The name of the D1 database to delete. |
55 | | -- `-y, --skip-confirmation` <Type text="boolean" /> <MetaInfo text="optional" /> |
56 | | - - Skip deletion confirmation prompt. |
57 | | - |
58 | | -<AnchorHeading title="`execute`" slug="d1-execute" depth={3} /> |
59 | | - |
60 | | -Execute a query on a D1 database. |
61 | | - |
62 | | -```txt |
63 | | -wrangler d1 execute <DATABASE_NAME> [OPTIONS] |
64 | | -``` |
65 | | - |
66 | | -:::note |
67 | | - |
68 | | -You must provide either `--command` or `--file` for this command to run successfully. |
69 | | - |
70 | | -::: |
71 | | - |
72 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
73 | | - - The name of the D1 database to execute a query on. |
74 | | -- `--command` <Type text="string" /> <MetaInfo text="optional" /> |
75 | | - - The SQL query you wish to execute. |
76 | | -- `--file` <Type text="string" /> <MetaInfo text="optional" /> |
77 | | - - Path to the SQL file you wish to execute. |
78 | | -- `-y, --yes` <Type text="boolean" /> <MetaInfo text="optional" /> |
79 | | - - Answer `yes` to any prompts. |
80 | | -- `--local` <Type text="boolean" /> <MetaInfo text="(default: true) optional" /> |
81 | | - - Execute commands/files against a local database for use with [wrangler dev](/workers/wrangler/commands/#dev). |
82 | | -- `--remote` <Type text="boolean" /> <MetaInfo text="(default: false) optional" /> |
83 | | - - Execute commands/files against a remote D1 database for use with [remote bindings](/workers/development-testing/#remote-bindings) or your deployed Worker. |
84 | | -- `--persist-to` <Type text="string" /> <MetaInfo text="optional" /> |
85 | | - - Specify directory to use for local persistence (for use in combination with `--local`). |
86 | | -- `--json` <Type text="boolean" /> <MetaInfo text="optional" /> |
87 | | - - Return output as JSON rather than a table. |
88 | | -- `--preview` <Type text="boolean" /> <MetaInfo text="optional" /> |
89 | | - - Execute commands/files against a preview D1 database (as defined by `preview_database_id` in the [Wrangler configuration file](/workers/wrangler/configuration/#d1-databases)). |
90 | | - |
91 | | -<AnchorHeading title="`export`" slug="d1-export" depth={3} /> |
92 | | - |
93 | | -Export a D1 database or table's schema and/or content to a `.sql` file. |
94 | | - |
95 | | -```txt |
96 | | -wrangler d1 export <DATABASE_NAME> [OPTIONS] |
97 | | -``` |
98 | | - |
99 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
100 | | - - The name of the D1 database to export. |
101 | | -- `--local` <Type text="boolean" /> <MetaInfo text="(default: true) optional" /> |
102 | | - - Export from a local database for use with [wrangler dev](/workers/wrangler/commands/#dev). |
103 | | -- `--remote` <Type text="boolean" /> <MetaInfo text="(default: false) optional" /> |
104 | | - - Export from a remote D1 database. |
105 | | -- `--output` <Type text="string" /> <MetaInfo text="required" /> |
106 | | - - Path to the SQL file for your export. |
107 | | -- `--table` <Type text="string" /> <MetaInfo text="optional" /> |
108 | | - - The name of the table within a D1 database to export. |
109 | | -- `--no-data` <Type text="boolean" /> <MetaInfo text="(default: false) optional" /> |
110 | | - - 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. |
111 | | -- `--no-schema` <Type text="boolean" /> <MetaInfo text="(default: false) optional" /> |
112 | | - - 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. |
113 | | - |
114 | | -<AnchorHeading |
115 | | - title="`time-travel restore`" |
116 | | - slug="d1-time-travel-restore" |
117 | | - depth={3} |
118 | | -/> |
119 | | - |
120 | | -Restore a database to a specific point-in-time using [Time Travel](/d1/reference/time-travel/). |
121 | | - |
122 | | -```txt |
123 | | -wrangler d1 time-travel restore <DATABASE_NAME> [OPTIONS] |
124 | | -``` |
125 | | - |
126 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
127 | | - - The name of the D1 database to execute a query on. |
128 | | -- `--bookmark` <Type text="string" /> <MetaInfo text="optional" /> |
129 | | - - A D1 bookmark representing the state of a database at a specific point in time. |
130 | | -- `--timestamp` <Type text="string" /> <MetaInfo text="optional" /> |
131 | | - - A UNIX timestamp or JavaScript date-time `string` within the last 30 days. |
132 | | -- `--json` <Type text="boolean" /> <MetaInfo text="optional" /> |
133 | | - - Return output as JSON rather than a table. |
134 | | - |
135 | | -<AnchorHeading |
136 | | - title="`time-travel info`" |
137 | | - slug="d1-time-travel-info" |
138 | | - depth={3} |
139 | | -/> |
140 | | - |
141 | | -Inspect the current state of a database for a specific point-in-time using [Time Travel](/d1/reference/time-travel/). |
142 | | - |
143 | | -```txt |
144 | | -wrangler d1 time-travel info <DATABASE_NAME> [OPTIONS] |
145 | | -``` |
146 | | - |
147 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
148 | | - - The name of the D1 database to execute a query on. |
149 | | -- `--timestamp` <Type text="string" /> <MetaInfo text="optional" /> |
150 | | - - A UNIX timestamp or JavaScript date-time `string` within the last 30 days. |
151 | | -- `--json` b<Type text="boolean" /> <MetaInfo text="optional" /> |
152 | | - - Return output as JSON rather than a table. |
153 | | - |
154 | | -<AnchorHeading |
155 | | - title="`migrations create`" |
156 | | - slug="d1-migrations-create" |
157 | | - depth={3} |
158 | | -/> |
159 | | - |
160 | | -Create a new migration. |
161 | | - |
162 | | -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: |
163 | | - |
164 | | -`0000_create_user_table.sql` |
165 | | - |
166 | | -The filename will include a version number and the migration name you specify below. |
167 | | - |
168 | | -```txt |
169 | | -wrangler d1 migrations create <DATABASE_NAME> <MIGRATION_NAME> |
170 | | -``` |
171 | | - |
172 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
173 | | - - The name of the D1 database you wish to create a migration for. |
174 | | -- `MIGRATION_NAME` <Type text="string" /> <MetaInfo text="required" /> |
175 | | - - A descriptive name for the migration you wish to create. |
176 | | - |
177 | | -<AnchorHeading title="`migrations list`" slug="d1-migrations-list" depth={3} /> |
178 | | - |
179 | | -View a list of unapplied migration files. |
180 | | - |
181 | | -```txt |
182 | | -wrangler d1 migrations list <DATABASE_NAME> [OPTIONS] |
183 | | -``` |
184 | | - |
185 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
186 | | - - The name of the D1 database you wish to list unapplied migrations for. |
187 | | -- `--local` <Type text="boolean" /> <MetaInfo text="optional" /> |
188 | | - - Show the list of unapplied migration files on your locally persisted D1 database. |
189 | | -- `--remote` <Type text="boolean" /> <MetaInfo text="(default: false) optional" /> |
190 | | - - Show the list of unapplied migration files on your remote D1 database. |
191 | | -- `--persist-to` <Type text="string" /> <MetaInfo text="optional" /> |
192 | | - - Specify directory to use for local persistence (for use in combination with `--local`). |
193 | | -- `--preview` <Type text="boolean" /> <MetaInfo text="optional" /> |
194 | | - - Show the list of unapplied migration files on your preview D1 database (as defined by `preview_database_id` in the [Wrangler configuration file](/workers/wrangler/configuration/#d1-databases)). |
195 | | - |
196 | | -<AnchorHeading |
197 | | - title="`migrations apply`" |
198 | | - slug="d1-migrations-apply" |
199 | | - depth={3} |
200 | | -/> |
201 | | - |
202 | | -Apply any unapplied migrations. |
203 | | - |
204 | | -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. |
205 | | - |
206 | | -The progress of each migration will be printed in the console. |
207 | | - |
208 | | -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. |
209 | | - |
210 | | -If applying a migration results in an error, this migration will be rolled back, and the previous successful migration will remain applied. |
211 | | - |
212 | | -```txt |
213 | | -wrangler d1 migrations apply <DATABASE_NAME> [OPTIONS] |
214 | | -``` |
215 | | - |
216 | | -- `DATABASE_NAME` <Type text="string" /> <MetaInfo text="required" /> |
217 | | - - The name of the D1 database you wish to apply your migrations on. |
218 | | -- `--env` <Type text="string" /> <MetaInfo text="optional" /> |
219 | | - - Specify which environment configuration to use for D1 binding |
220 | | -- `--local` <Type text="boolean" /> <MetaInfo text="(default: true) optional" /> |
221 | | - - Execute any unapplied migrations on your locally persisted D1 database. |
222 | | -- `--remote` <Type text="boolean" /> <MetaInfo text="(default: false) optional" /> |
223 | | - - Execute any unapplied migrations on your remote D1 database. |
224 | | -- `--persist-to` <Type text="string" /> <MetaInfo text="optional" /> |
225 | | - - Specify directory to use for local persistence (for use in combination with `--local`). |
226 | | -- `--preview` <Type text="boolean" /> <MetaInfo text="optional" /> |
227 | | - - Execute any unapplied migrations on your preview D1 database (as defined by `preview_database_id` in the [Wrangler configuration file](/workers/wrangler/configuration/#d1-databases)). |
| 7 | +<WranglerNamespace namespace="d1" /> |
0 commit comments