- A Neki database with a ready branch.
- An application role for that branch. Use
pg_read_all_datafor read traffic and addpg_write_all_datawhen the application writes rows. These inherited data roles do not grantCREATEorALTER, so application credentials cannot change the schema. - A separate migration role, if you run schema changes against the branch. DDL
requires the
postgresinherited role. Neki restricts execution of the cross-router DDL barrier function__neki.wait_for_ddlto itsneki_viewerrole, so addneki_viewer, which requirespg_read_all_data, to the same role. Keep the migration credentials out of the application’s runtime configuration. - The Primary connection details from the database’s Connect page.
Create a Workers project
Create a TypeScript Worker and installpg:
Create a Hyperdrive configuration
Cloudflare Hyperdrive requires apg version newer than 8.16.3.
Download the ISRG Root X1 certificate in PEM format from
Let’s Encrypt, then upload the single
certificate to Cloudflare:
sslmode and sslrootcert query parameters. Hyperdrive configures TLS to the
Neki origin separately from the connection URI.
Create the Hyperdrive configuration with the CA certificate ID and
verify-full SSL mode:
verify-full verifies the certificate chain and checks that the Neki hostname
matches the certificate. See Cloudflare’s
Hyperdrive TLS configuration
for details. Wrangler verifies the database connection before creating the
configuration.
The command returns a Hyperdrive ID. Add that ID to wrangler.jsonc. Use a
recent compatibility_date rather than a hardcoded older date:
wrangler.jsonc
Query Neki from the Worker
Create apg client from the Hyperdrive connection string:
src/index.ts
client.end(). See Cloudflare’s
connection lifecycle
guidance.
Deploy the Worker:
Hyperdrive can cache eligible read queries. Its cache does not automatically
invalidate after an application write. Disable caching for reads that require
read-after-write consistency.
Apply schema changes
Framework migration commands send DDL through a normal Neki connection. The
router fans that DDL out to the managed shards, but it does not create a
managed schema-change workflow. Use a schema-change
workflow when you want Neki to prepare and coordinate
an Online DDL change.
pg_read_all_data and pg_write_all_data
cannot run CREATE or ALTER, so a migration that uses application
credentials fails on its first DDL statement.
Apply migration DDL with psql and the migration role so the client prints
PostgreSQL notices:
NOTICE containing the barrier call
for that transaction:
psql when the framework cannot preserve
the notice. If the notice is lost, its version pair cannot be reconstructed.
Run schema migrations outside the Worker through a direct Neki connection.
Hyperdrive’s transaction pooling does not preserve the per-session state or
notices required by the DDL barrier workflow.
Hyperdrive does not currently provide a documented way to pass Neki’s replica
startup option to its origin connections. Keep Hyperdrive traffic on the
primary target.

