Kernlift
Database

Use Postgres and Supabase

Point the app at any Postgres database, including Supabase and Neon, and build its schema from the migration chain.

Any Postgres database works through the generic Drizzle Postgres adapter. Supabase and Neon are hosted Postgres endpoints on the same code path. The app uses no Supabase SDK, auth helper, storage API or row-level security.

Before you begin

  • A Postgres database and its connection string, for example from Supabase Project Settings → Database.
  • A machine that can reach the database to run migrations.
  • An empty database. A schema created by something other than the migration chain cannot be migrated in place.

Create the database with the host

ProviderChoose it for
SupabaseDirect connection or session pooler
NeonBranch-specific connection strings

Connect the database

Set the connection

.env
DATABASE_DIALECT=postgres
DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/postgres

DATABASE_ADAPTER can stay unset; it defaults to postgres.

Build the schema

pnpm db:migrate

This applies the Postgres chain under drizzle/migrations/postgres.

Create the administrator

SUPER_ADMIN_EMAIL=you@example.com SUPER_ADMIN_PASSWORD='<password>' pnpm db:bootstrap-super-admin

Keep credentials server-side

Never expose the connection string or a Supabase service-role key to client code. If Supabase's Data API already exposes these tables, restrict role grants and enable and review row-level security; this application's server permissions do not automatically protect that API.

Using a hosted Postgres database

Supabase and Neon use the same Postgres adapter and migration chain. Prefer direct connection for migrations and the runtime connection chosen above for the application; no provider SDK is needed. Schema changes require a matching migration in both the Postgres and SQLite chains.

Where the connection goes in production

How a deployment reaches Postgres depends on the platform recorded in deploy.config.json. The steps above cover local use and migrating from a checkout; in production the connection is supplied like this:

PlatformHow the app connectsHow the schema is migrated
CloudflareThrough Hyperdrive: DATABASE_ADAPTER=hyperdrive and the HYPERDRIVE binding in wrangler.jsonc. The Worker never holds DATABASE_URLpnpm db:migrate from the checkout, with DATABASE_URL set to the Postgres URL
Fly.ioDATABASE_URL as an app secretrelease_command on each deploy
RailwayThe Postgres declared in .railway/railway.ts; its DATABASE_URL is passed to the servicesThe pre-deploy step of the web service
DockerThe bundled postgres compose service, with POSTGRES_PASSWORD from .env.productionThe migrate compose service

On Workers the Postgres client lives for one request and Hyperdrive pools the connections behind it. See Deploy to Cloudflare Workers, Deploy to Fly.io, Deploy to Railway and Deploy with Docker Compose.

Verify

pnpm validate:db-adapters

Then start the app, sign in as the administrator and open /admin.

Troubleshooting

DATABASE_URL is required when DATABASE_ADAPTER=postgres

The connection string is empty. Set DATABASE_URL.

pnpm db:migrate reports an existing schema

Tables exist that the migration chain did not create. Drop and recreate the database, then run pnpm db:migrate again.

Do I run pnpm db:generate?

No. Generate writes a new migration for a schema change; it does not prepare a database.

Reference

Next steps