Skip to content

Commit a1940b2

Browse files
committed
rename hyperdrive env var with cloudflare prefix
1 parent a4e2439 commit a1940b2

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

.changeset/tidy-baboons-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Rename Hyperdrive local connection string environment variable from `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>` to `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>`. The old variable name is still supported but will now show a deprecation warning.

packages/wrangler/e2e/dev.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ describe("hyperdrive dev tests", () => {
684684
const worker = helper.runLongLived("wrangler dev", {
685685
env: {
686686
...process.env,
687-
WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE: `postgresql://user:[email protected]:${port}/some_db`,
687+
CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE: `postgresql://user:[email protected]:${port}/some_db`,
688688
},
689689
});
690690

packages/wrangler/src/dev.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -911,27 +911,39 @@ export function getBindings(
911911

912912
// Hyperdrive bindings
913913
const hyperdriveBindings = configParam.hyperdrive.map((hyperdrive) => {
914-
const connectionStringFromEnv =
915-
process.env[
916-
`WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${hyperdrive.binding}`
917-
];
914+
const desiredPrefix = `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_`;
915+
const deprecatedPrefix = `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_`;
916+
917+
let varName = `${deprecatedPrefix}${hyperdrive.binding}`;
918+
let connectionStringFromEnv = process.env[varName];
919+
920+
if (!connectionStringFromEnv) {
921+
varName = `${desiredPrefix}${hyperdrive.binding}`;
922+
connectionStringFromEnv = process.env[varName];
923+
}
924+
918925
// only require a local connection string in the wrangler file or the env if not using dev --remote
919926
if (
920927
local &&
921928
connectionStringFromEnv === undefined &&
922929
hyperdrive.localConnectionString === undefined
923930
) {
924931
throw new UserError(
925-
`When developing locally, you should use a local Postgres connection string to emulate Hyperdrive functionality. Please setup Postgres locally and set the value of the 'WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${hyperdrive.binding}' variable or "${hyperdrive.binding}"'s "localConnectionString" to the Postgres connection string.`,
932+
`When developing locally, you should use a local Postgres connection string to emulate Hyperdrive functionality. Please setup Postgres locally and set the value of the '${desiredPrefix}${hyperdrive.binding}' variable or "${hyperdrive.binding}"'s "localConnectionString" to the Postgres connection string.`,
926933
{ telemetryMessage: "no local hyperdrive connection string" }
927934
);
928935
}
929936

930937
// If there is a non-empty connection string specified in the environment,
931938
// use that as our local connection string configuration.
932939
if (connectionStringFromEnv) {
940+
if (varName.startsWith(deprecatedPrefix)) {
941+
logger.once.warn(
942+
`Using "${deprecatedPrefix}<BINDING_NAME>" environment variable. This is deprecated. Please use "${desiredPrefix}<BINDING_NAME>", instead.`
943+
);
944+
}
933945
logger.log(
934-
`Found a non-empty WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING variable for binding. Hyperdrive will connect to this database during local development.`
946+
`Found a non-empty ${varName} variable for binding. Hyperdrive will connect to this database during local development.`
935947
);
936948
hyperdrive.localConnectionString = connectionStringFromEnv;
937949
}

packages/wrangler/src/environment-variables/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type VariableNames =
2525
// ## Development & Local Testing
2626

2727
/** Local database connection strings for Hyperdrive development. The * should be replaced with the Hyperdrive binding name in the Worker. */
28-
| `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${string}`
28+
| `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_${string}`
2929
/** Suppress Hyperdrive-related warnings during development. */
3030
| "NO_HYPERDRIVE_WARNING"
3131
/** Path to HTTPS private key file for running the local development server in HTTPS mode. Without this Wrangler will generate keys automatically. */

0 commit comments

Comments
 (0)