Skip to main content
For production on Cloudflare Workers, use PostgreSQL through a Hyperdrive binding. Hyperdrive supplies the connection string consumed by Hookfish’s PostgreSQL adapter and manages the underlying connection pool.

Create the Worker

The Cloudflare scaffold configures the PostgreSQL adapter and generates a placeholder Hyperdrive binding:
Create a Hyperdrive configuration for your PostgreSQL database. Replace the placeholder ID in wrangler.jsonc with its configuration ID. The comments in that file include the remaining local setup and migration steps.

Generated database binding

The generated src/index.ts resolves the Hyperdrive binding for each request:
cache: false prevents the adapter from retaining request-owned database clients in module state. Hyperdrive manages the underlying pool. max: 5 stays below the Worker request’s concurrent external-connection limit.

Configure local PostgreSQL

Set the local connection string for the HYPERDRIVE binding, then generate types and start Wrangler:
Keep the real connection string out of source control and shell history. Local Wrangler connects directly to PostgreSQL; Hyperdrive caching does not run in local mode.

Run migrations

Put a direct PostgreSQL connection string in the generated .env file. Run the generated migration command from CI or another trusted environment that can connect directly to the database:
Do not run schema migrations through a user request or on every Worker startup.

Store secrets and deploy

Use Wrangler’s interactive secret prompts:
After deployment, set OAUTH_REDIRECT_BASE_URL to the Worker’s public HTTPS origin and register the callback URLs reported by Hookfish.