Skip to content

Commit

Permalink
[D1] clean-up validation and epilogue (#4006)
Browse files Browse the repository at this point in the history
* teach wrangler about d1 beta

* Create lazy-clocks-exist.md

* don't log a warning for every command
  • Loading branch information
rozenmd authored Sep 21, 2023
1 parent fd39ae6 commit bc8c147
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 86 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-clocks-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: remove warning around using D1's binding, and clean up the epilogue when running D1 commands
12 changes: 3 additions & 9 deletions packages/wrangler/src/__tests__/d1/d1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ describe("d1", () => {
-v, --version Show version number [boolean]
--------------------
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
🚧 D1 is currently in open beta
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
🚧 To give feedback, visit https://discord.gg/cloudflaredev
--------------------"
`);
});
Expand Down Expand Up @@ -76,10 +74,8 @@ describe("d1", () => {
-v, --version Show version number [boolean]
--------------------
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
🚧 D1 is currently in open beta
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
🚧 To give feedback, visit https://discord.gg/cloudflaredev
--------------------"
`);
});
Expand Down Expand Up @@ -113,10 +109,8 @@ describe("d1", () => {
-v, --version Show version number [boolean]
--------------------
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
🚧 D1 is currently in open beta
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
🚧 To give feedback, visit https://discord.gg/cloudflaredev
--------------------"
`);
});
Expand Down
12 changes: 1 addition & 11 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6400,17 +6400,7 @@ addEventListener('fetch', event => {});`
--dry-run: exiting now."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] Processing wrangler.toml configuration:
- D1 Bindings are currently in alpha to allow the API to evolve before general availability.
Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
Note: Run this command with the environment variable NO_D1_WARNING=true to hide this message
For example: \`export NO_D1_WARNING=true && wrangler <YOUR COMMAND HERE>\`
"
`);
expect(std.warn).toMatchInlineSnapshot(`""`);
const output = fs.readFileSync("tmp/index.js", "utf-8");
// D1 no longer injects middleware, so we can pass through the user's code unchanged
expect(output).not.toContain(`ExampleDurableObject2`);
Expand Down
6 changes: 1 addition & 5 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2249,11 +2249,7 @@ const validateD1Binding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}
if (isValid && !process.env.NO_D1_WARNING) {
diagnostics.warnings.push(
"D1 Bindings are currently in alpha to allow the API to evolve before general availability.\nPlease report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose\nNote: Run this command with the environment variable NO_D1_WARNING=true to hide this message\n\nFor example: `export NO_D1_WARNING=true && wrangler <YOUR COMMAND HERE>`"
);
}

return isValid;
};

Expand Down
10 changes: 5 additions & 5 deletions packages/wrangler/src/d1/backups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { requireAuth } from "../user";
import { renderToString } from "../utils/render";
import { formatBytes, formatTimeAgo } from "./formatTimeAgo";
import { Name } from "./options";
import { d1BetaWarning, getDatabaseByNameOrBinding } from "./utils";
import { getDatabaseByNameOrBinding } from "./utils";
import type {
CommonYargsArgv,
StrictYargsOptionsToInterface,
Expand All @@ -25,7 +25,7 @@ type ListHandlerOptions = StrictYargsOptionsToInterface<typeof ListOptions>;
export const ListHandler = withConfig<ListHandlerOptions>(
async ({ config, name }): Promise<void> => {
const accountId = await requireAuth(config);
logger.log(d1BetaWarning);

const db: Database = await getDatabaseByNameOrBinding(
config,
accountId,
Expand Down Expand Up @@ -88,7 +88,7 @@ type CreateHandlerOptions = StrictYargsOptionsToInterface<typeof CreateOptions>;
export const CreateHandler = withConfig<CreateHandlerOptions>(
async ({ config, name }): Promise<void> => {
const accountId = await requireAuth(config);
logger.log(d1BetaWarning);

const db: Database = await getDatabaseByNameOrBinding(
config,
accountId,
Expand Down Expand Up @@ -136,7 +136,7 @@ type RestoreHandlerOptions = StrictYargsOptionsToInterface<
export const RestoreHandler = withConfig<RestoreHandlerOptions>(
async ({ config, name, backupId }): Promise<void> => {
const accountId = await requireAuth(config);
logger.log(d1BetaWarning);

const db: Database = await getDatabaseByNameOrBinding(
config,
accountId,
Expand Down Expand Up @@ -184,7 +184,7 @@ type DownloadHandlerOptions = StrictYargsOptionsToInterface<
export const DownloadHandler = withConfig<DownloadHandlerOptions>(
async ({ name, backupId, output, config }): Promise<void> => {
const accountId = await requireAuth(config);
logger.log(d1BetaWarning);

const db: Database = await getDatabaseByNameOrBinding(
config,
accountId,
Expand Down
2 changes: 0 additions & 2 deletions packages/wrangler/src/d1/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export const Handler = withConfig<HandlerOptions>(
async ({ name, config, location }): Promise<void> => {
const accountId = await requireAuth(config);

logger.log(d1BetaWarning);

if (location) {
if (LOCATION_CHOICES.indexOf(location.toLowerCase()) === -1) {
throw new Error(
Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/src/d1/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type HandlerOptions = StrictYargsOptionsToInterface<typeof Options>;
export const Handler = withConfig<HandlerOptions>(
async ({ name, skipConfirmation, config }): Promise<void> => {
const accountId = await requireAuth(config);
logger.log(d1BetaWarning);

const db: Database = await getDatabaseByNameOrBinding(
config,
Expand Down
8 changes: 2 additions & 6 deletions packages/wrangler/src/d1/execute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import { renderToString } from "../utils/render";
import { DEFAULT_BATCH_SIZE } from "./constants";
import * as options from "./options";
import splitSqlQuery from "./splitter";
import {
d1BetaWarning,
getDatabaseByNameOrBinding,
getDatabaseInfoFromConfig,
} from "./utils";
import { getDatabaseByNameOrBinding, getDatabaseInfoFromConfig } from "./utils";
import type { Config, ConfigFields, DevConfig, Environment } from "../config";
import type {
CommonYargsArgv,
Expand Down Expand Up @@ -102,7 +98,7 @@ export const Handler = async (args: HandlerOptions): Promise<void> => {
logger.loggerLevel = "error";
}
const config = readConfig(args.config, args);
logger.log(d1BetaWarning);

if (file && command)
return logger.error(`Error: can't provide both --command and --file.`);

Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/src/d1/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const Handler = withConfig<HandlerOptions>(
if (json) {
logger.log(JSON.stringify(dbs, null, 2));
} else {
logger.log(d1BetaWarning);
logger.log(renderToString(<Table data={dbs}></Table>));
}
}
Expand Down
8 changes: 1 addition & 7 deletions packages/wrangler/src/d1/migrations/apply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ import {
DEFAULT_BATCH_SIZE,
} from "../constants";
import { executeSql } from "../execute";
import {
d1BetaWarning,
getDatabaseInfoFromConfig,
getDatabaseInfoFromId,
} from "../utils";
import { getDatabaseInfoFromConfig, getDatabaseInfoFromId } from "../utils";
import {
getMigrationsPath,
getUnappliedMigrations,
Expand Down Expand Up @@ -54,8 +50,6 @@ export const ApplyHandler = withConfig<ApplyHandlerOptions>(
preview,
batchSize,
}): Promise<void> => {
logger.log(d1BetaWarning);

const databaseInfo = getDatabaseInfoFromConfig(config, database);
if (!databaseInfo && !local) {
throw new Error(
Expand Down
4 changes: 1 addition & 3 deletions packages/wrangler/src/d1/migrations/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { logger } from "../../logger";
import { renderToString } from "../../utils/render";
import { DEFAULT_MIGRATION_PATH } from "../constants";
import { Database } from "../options";
import { d1BetaWarning, getDatabaseInfoFromConfig } from "../utils";
import { getDatabaseInfoFromConfig } from "../utils";
import { getMigrationsPath, getNextMigrationNumber } from "./helpers";
import type {
CommonYargsArgv,
Expand All @@ -26,8 +26,6 @@ type CreateHandlerOptions = StrictYargsOptionsToInterface<typeof CreateOptions>;

export const CreateHandler = withConfig<CreateHandlerOptions>(
async ({ config, database, message }): Promise<void> => {
logger.log(d1BetaWarning);

const databaseInfo = getDatabaseInfoFromConfig(config, database);
if (!databaseInfo) {
throw new Error(
Expand Down
3 changes: 1 addition & 2 deletions packages/wrangler/src/d1/migrations/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { logger } from "../../logger";
import { requireAuth } from "../../user";
import { renderToString } from "../../utils/render";
import { DEFAULT_MIGRATION_PATH, DEFAULT_MIGRATION_TABLE } from "../constants";
import { d1BetaWarning, getDatabaseInfoFromConfig } from "../utils";
import { getDatabaseInfoFromConfig } from "../utils";
import {
getMigrationsPath,
getUnappliedMigrations,
Expand All @@ -30,7 +30,6 @@ export const ListHandler = withConfig<ListHandlerOptions>(
if (!local) {
await requireAuth({});
}
logger.log(d1BetaWarning);

const databaseInfo = getDatabaseInfoFromConfig(config, database);
if (!databaseInfo && !local) {
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/d1/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const getDatabaseByNameOrBinding = async (

export const d1BetaWarning = process.env.NO_D1_WARNING
? ""
: "--------------------\n🚧 D1 is currently in open alpha and is not recommended for production data and traffic\n🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose\n🚧 To request features, visit https://community.cloudflare.com/c/developers/d1\n🚧 To give feedback, visit https://discord.gg/cloudflaredev\n--------------------\n";
: "--------------------\n🚧 D1 is currently in open beta\n🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose\n--------------------\n";

export const getDatabaseInfoFromId = async (
accountId: string,
Expand Down
Loading

0 comments on commit bc8c147

Please sign in to comment.