Skip to main content
Database production memakai Neon — Postgres serverless. Connection string disimpan di .env.production.local (bukan di .env shared kalau beda dengan DB lokal).
Logo Neon
Console: console.neon.tech
Docs: neon.com/docs

Env di project

# .env.production.local (override prod)
DATABASE_URL=postgresql://user:pass@ep-xxx-pooler.region.aws.neon.tech/neondb?sslmode=require
Dev lokal biasanya Postgres di laptop — override di .env.development.local:
DATABASE_URL=postgresql://trainerhub_beta:...@127.0.0.1:5432/trainerhub_beta_clean

Setup Neon (pertama kali)

1

Buat project

Neon ConsoleNew Project → pilih region (dekat user / Cloudflare)
2

Ambil connection string

Project Dashboard → tombol Connect → pilih:
  • Branch: main / production
  • Connection pooling: ON (hostname berisi -pooler) — disarankan untuk Workers
  • Copy string postgresql://...
3

Simpan aman

Paste ke .env.production.local sebagai DATABASE_URL.
Jangan commit — file ini di-gitignore.
4

Migrate saat deploy

./thub deploy / deploy-prod.sh menjalankan migrate SQL ke DATABASE_URL production.

Pooled vs direct

TipeKapan dipakai
Pooled (-pooler di hostname)Runtime app, Workers via Hyperdrive
Direct (tanpa pooler)Migration berat, psql, tooling satu koneksi panjang
Neon docs: Connection pooling

Verifikasi koneksi

./thub env merge --prod
psql "$DATABASE_URL" -c "SELECT 1"
./thub doctor

CI/CD (GitHub Actions)

Secret DATABASE_URL di environment production — isi sama dengan Neon production. Script ci-materialize-env.sh menulis ke .env.production.local sebelum deploy.

Troubleshooting

MasalahSolusi
SSL requiredPastikan ?sslmode=require di URL
Too many connectionsPakai pooled URL atau Hyperdrive
Migrate gagal di CICek IP allowlist Neon (biasanya open untuk Neon cloud)
Doctor DB merah di lokalNormal jika Postgres lokal belum jalan — override dev URL