Skip to content

Commit 45480b1

Browse files
authored
CFSQL-1406 update wrangler d1 ... --help output from Cloudflare Docs site (#11393)
* CFSQL-1406 copy some wrangler d1 help text from cloudflare docs site * CFSQL-1406 reorder D1 commands to match cloudflare docs site * CFSQL-1406 explicitly state whether D1 commands act on local/remote by default
1 parent 643f9e8 commit 45480b1

File tree

15 files changed

+98
-50
lines changed

15 files changed

+98
-50
lines changed

‎.changeset/loose-games-camp.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
improved --help text for wrangler d1 subcommands

‎packages/wrangler/src/__tests__/d1/d1.test.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ describe("d1", () => {
1818
🗄 Manage Workers D1 databases
1919
2020
COMMANDS
21-
wrangler d1 list List D1 databases
21+
wrangler d1 create <name> Creates a new D1 database, and provides the binding and UUID that you will put in your config file
2222
wrangler d1 info <name> Get information about a D1 database, including the current database size and state
23-
wrangler d1 insights <name> Get information about the queries run on a D1 database. [experimental]
24-
wrangler d1 create <name> Create D1 database
25-
wrangler d1 delete <name> Delete D1 database
23+
wrangler d1 list List all D1 databases in your account
24+
wrangler d1 delete <name> Delete a D1 database
2625
wrangler d1 execute <database> Execute a command or SQL file
2726
wrangler d1 export <name> Export the contents or schema of your database as a .sql file
2827
wrangler d1 time-travel Use Time Travel to restore, fork or copy a database at a specific point-in-time
2928
wrangler d1 migrations Interact with D1 migrations
29+
wrangler d1 insights <name> Get information about the queries run on a D1 database [experimental]
3030
3131
GLOBAL FLAGS
3232
-c, --config Path to Wrangler configuration file [string]
@@ -55,15 +55,15 @@ describe("d1", () => {
5555
🗄 Manage Workers D1 databases
5656
5757
COMMANDS
58-
wrangler d1 list List D1 databases
58+
wrangler d1 create <name> Creates a new D1 database, and provides the binding and UUID that you will put in your config file
5959
wrangler d1 info <name> Get information about a D1 database, including the current database size and state
60-
wrangler d1 insights <name> Get information about the queries run on a D1 database. [experimental]
61-
wrangler d1 create <name> Create D1 database
62-
wrangler d1 delete <name> Delete D1 database
60+
wrangler d1 list List all D1 databases in your account
61+
wrangler d1 delete <name> Delete a D1 database
6362
wrangler d1 execute <database> Execute a command or SQL file
6463
wrangler d1 export <name> Export the contents or schema of your database as a .sql file
6564
wrangler d1 time-travel Use Time Travel to restore, fork or copy a database at a specific point-in-time
6665
wrangler d1 migrations Interact with D1 migrations
66+
wrangler d1 insights <name> Get information about the queries run on a D1 database [experimental]
6767
6868
GLOBAL FLAGS
6969
-c, --config Path to Wrangler configuration file [string]
@@ -85,9 +85,9 @@ describe("d1", () => {
8585
Interact with D1 migrations
8686
8787
COMMANDS
88-
wrangler d1 migrations list <database> List your D1 migrations
8988
wrangler d1 migrations create <database> <message> Create a new migration
90-
wrangler d1 migrations apply <database> Apply D1 migrations
89+
wrangler d1 migrations list <database> View a list of unapplied migration files
90+
wrangler d1 migrations apply <database> Apply any unapplied D1 migrations
9191
9292
GLOBAL FLAGS
9393
-c, --config Path to Wrangler configuration file [string]

‎packages/wrangler/src/d1/create.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ export async function createD1Database(
5050

5151
export const d1CreateCommand = createCommand({
5252
metadata: {
53-
description: "Create D1 database",
53+
description:
54+
"Creates a new D1 database, and provides the binding and UUID that you will put in your config file",
55+
epilogue: "This command acts on remote D1 Databases.",
5456
status: "stable",
5557
owner: "Product: D1",
5658
},
5759
args: {
5860
name: {
5961
type: "string",
6062
demandOption: true,
61-
description: "The name of the new DB",
63+
description: "The name of the new D1 database",
6264
},
6365
location: {
6466
type: "string",

‎packages/wrangler/src/d1/delete.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import type { Database } from "./types";
1010

1111
export const d1DeleteCommand = createCommand({
1212
metadata: {
13-
description: "Delete D1 database",
13+
description: "Delete a D1 database",
1414
status: "stable",
15+
epilogue: "This command acts on remote D1 Databases.",
1516
owner: "Product: D1",
1617
},
1718
behaviour: {

‎packages/wrangler/src/d1/execute.ts‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export const d1ExecuteCommand = createCommand({
4646
description: "Execute a command or SQL file",
4747
status: "stable",
4848
owner: "Product: D1",
49+
epilogue:
50+
"You must provide either --command or --file for this command to run successfully.",
4951
},
5052
behaviour: {
5153
printBanner: (args) => !args.json,
@@ -57,6 +59,15 @@ export const d1ExecuteCommand = createCommand({
5759
demandOption: true,
5860
description: "The name or binding of the DB",
5961
},
62+
command: {
63+
type: "string",
64+
description:
65+
"The SQL query you wish to execute, or multiple queries separated by ';'",
66+
},
67+
file: {
68+
type: "string",
69+
description: "A .sql file to ingest",
70+
},
6071
yes: {
6172
type: "boolean",
6273
description: 'Answer "yes" to any prompts',
@@ -70,20 +81,12 @@ export const d1ExecuteCommand = createCommand({
7081
remote: {
7182
type: "boolean",
7283
description:
73-
"Execute commands/files against a remote DB for use with wrangler dev",
74-
},
75-
file: {
76-
type: "string",
77-
description: "A .sql file to ingest",
78-
},
79-
command: {
80-
type: "string",
81-
description: "A single SQL statement to execute",
84+
"Execute commands/files against a remote D1 database for use with remote bindings or your deployed Worker",
8285
},
8386
"persist-to": {
8487
type: "string",
8588
description:
86-
"Specify directory to use for local persistence (for --local)",
89+
"Specify directory to use for local persistence (for use with --local)",
8790
requiresArg: true,
8891
},
8992
json: {
@@ -93,7 +96,7 @@ export const d1ExecuteCommand = createCommand({
9396
},
9497
preview: {
9598
type: "boolean",
96-
description: "Execute commands/files against a preview D1 DB",
99+
description: "Execute commands/files against a preview D1 database",
97100
default: false,
98101
},
99102
},

‎packages/wrangler/src/d1/export.ts‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const d1ExportCommand = createCommand({
2929
name: {
3030
type: "string",
3131
demandOption: true,
32-
description: "The name of the DB",
32+
description: "The name of the D1 database to export",
3333
},
3434
local: {
3535
type: "boolean",
@@ -38,9 +38,18 @@ export const d1ExportCommand = createCommand({
3838
},
3939
remote: {
4040
type: "boolean",
41-
description: "Export from your live D1",
41+
description: "Export from a remote D1 database",
4242
conflicts: "local",
4343
},
44+
output: {
45+
type: "string",
46+
description: "Path to the SQL file for your export",
47+
demandOption: true,
48+
},
49+
table: {
50+
type: "string",
51+
description: "Specify which tables to include in export",
52+
},
4453
"no-schema": {
4554
type: "boolean",
4655
description: "Only output table contents, not the DB schema",
@@ -64,15 +73,6 @@ export const d1ExportCommand = createCommand({
6473
hidden: true,
6574
default: true,
6675
},
67-
table: {
68-
type: "string",
69-
description: "Specify which tables to include in export",
70-
},
71-
output: {
72-
type: "string",
73-
description: "Which .sql file to output to",
74-
demandOption: true,
75-
},
7676
},
7777
positionalArgs: ["name"],
7878
async handler(args, { config }) {

‎packages/wrangler/src/d1/info.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const d1InfoCommand = createCommand({
1313
metadata: {
1414
description:
1515
"Get information about a D1 database, including the current database size and state",
16+
epilogue: "This command acts on remote D1 Databases.",
1617
status: "stable",
1718
owner: "Product: D1",
1819
},

‎packages/wrangler/src/d1/insights.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export function getDurationDates(durationString: string) {
5656

5757
export const d1InsightsCommand = createCommand({
5858
metadata: {
59-
description: "Get information about the queries run on a D1 database.",
59+
description: "Get information about the queries run on a D1 database",
60+
epilogue: "This command acts on remote D1 Databases.",
6061
status: "experimental",
6162
owner: "Product: D1",
6263
},

‎packages/wrangler/src/d1/list.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import type { ComplianceConfig } from "@cloudflare/workers-utils";
77

88
export const d1ListCommand = createCommand({
99
metadata: {
10-
description: "List D1 databases",
10+
description: "List all D1 databases in your account",
11+
epilogue: "This command acts on remote D1 Databases.",
1112
status: "stable",
1213
owner: "Product: D1",
1314
},

‎packages/wrangler/src/d1/migrations/apply.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from "node:fs";
22
import path from "node:path";
33
import { configFileName, UserError } from "@cloudflare/workers-utils";
4+
import dedent from "ts-dedent";
45
import { createCommand } from "../../core/create-command";
56
import { confirm } from "../../dialogs";
67
import { isNonInteractiveOrCI } from "../../is-interactive";
@@ -17,7 +18,20 @@ import type { ParseError } from "@cloudflare/workers-utils";
1718

1819
export const d1MigrationsApplyCommand = createCommand({
1920
metadata: {
20-
description: "Apply D1 migrations",
21+
description: "Apply any unapplied D1 migrations",
22+
epilogue: dedent`
23+
This command will prompt you to confirm the migrations you are about to apply.
24+
Confirm that you would like to proceed. After applying, a backup will be captured.
25+
26+
The progress of each migration will be printed in the console.
27+
28+
When running the apply command in a CI/CD environment or another non-interactive
29+
command line, the confirmation step will be skipped, but the backup will still be
30+
captured.
31+
32+
If applying a migration results in an error, this migration will be rolled back,
33+
and the previous successful migration will remain applied.
34+
`,
2135
status: "stable",
2236
owner: "Product: D1",
2337
},

0 commit comments

Comments
 (0)