Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-baboons-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

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.
2 changes: 1 addition & 1 deletion packages/wrangler/e2e/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ describe("hyperdrive dev tests", () => {
const worker = helper.runLongLived("wrangler dev", {
env: {
...process.env,
WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE: `postgresql://user:[email protected]:${port}/some_db`,
CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE: `postgresql://user:[email protected]:${port}/some_db`,
},
});

Expand Down
24 changes: 18 additions & 6 deletions packages/wrangler/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,27 +911,39 @@ export function getBindings(

// Hyperdrive bindings
const hyperdriveBindings = configParam.hyperdrive.map((hyperdrive) => {
const connectionStringFromEnv =
process.env[
`WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${hyperdrive.binding}`
];
const desiredPrefix = `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_`;
const deprecatedPrefix = `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_`;

let varName = `${deprecatedPrefix}${hyperdrive.binding}`;
let connectionStringFromEnv = process.env[varName];

if (!connectionStringFromEnv) {
varName = `${desiredPrefix}${hyperdrive.binding}`;
connectionStringFromEnv = process.env[varName];
}

// only require a local connection string in the wrangler file or the env if not using dev --remote
if (
local &&
connectionStringFromEnv === undefined &&
hyperdrive.localConnectionString === undefined
) {
throw new UserError(
`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.`,
`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.`,
{ telemetryMessage: "no local hyperdrive connection string" }
);
}

// If there is a non-empty connection string specified in the environment,
// use that as our local connection string configuration.
if (connectionStringFromEnv) {
if (varName.startsWith(deprecatedPrefix)) {
logger.once.warn(
`Using "${deprecatedPrefix}<BINDING_NAME>" environment variable. This is deprecated. Please use "${desiredPrefix}<BINDING_NAME>", instead.`
);
}
logger.log(
`Found a non-empty WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING variable for binding. Hyperdrive will connect to this database during local development.`
`Found a non-empty ${varName} variable for binding. Hyperdrive will connect to this database during local development.`
);
hyperdrive.localConnectionString = connectionStringFromEnv;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/environment-variables/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type VariableNames =
// ## Development & Local Testing

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