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
| Provider | Choose it for |
|---|---|
| Supabase | Direct connection or session pooler |
| Neon | Branch-specific connection strings |
Connect the database
Set the connection
DATABASE_DIALECT=postgres
DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/postgresDATABASE_ADAPTER can stay unset; it defaults to postgres.
Create the administrator
SUPER_ADMIN_EMAIL=you@example.com SUPER_ADMIN_PASSWORD='<password>' pnpm db:bootstrap-super-adminKeep 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:
| Platform | How the app connects | How the schema is migrated |
|---|---|---|
| Cloudflare | Through Hyperdrive: DATABASE_ADAPTER=hyperdrive and the HYPERDRIVE binding in wrangler.jsonc. The Worker never holds DATABASE_URL | pnpm db:migrate from the checkout, with DATABASE_URL set to the Postgres URL |
| Fly.io | DATABASE_URL as an app secret | release_command on each deploy |
| Railway | The Postgres declared in .railway/railway.ts; its DATABASE_URL is passed to the services | The pre-deploy step of the web service |
| Docker | The bundled postgres compose service, with POSTGRES_PASSWORD from .env.production | The 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-adaptersThen 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
- Environment variables
- Deployment model
- Postgres.js: the driver this adapter loads
- Supabase connection strings