Database Branching untuk CI/CD: Tutorial PostgreSQL + Neon di Helipod
이 글은 인도네시아어로 작성되었습니다.
Bayangkan setiap pull request di GitHub otomatis punya database branch sendiri, tanpa setup manual, tanpa tunggu menit, tanpa takut ngotorin production.
Itu bukan mimpi. Dengan Neon database branching + Helipod, itu jadi kenyataan.
Kenapa Database Branching untuk CI/CD?#
Masalah Tanpa Branching#
Developer A push code → Testing di staging → Database conflict!
Developer B push code → Testing di staging → Data campur aduk!
Akhirnya:
- Manual setup database buat testing
- Sering lupa cleanup branch lama
- Staging database sering "kotor" karena dipakai bareng
Solusi: Database Branching#
Pull Request #1 → Branch DB pr-1 → Isolated testing
Pull Request #2 → Branch DB pr-2 → Isolated testing
Pull Request #3 → Branch DB pr-3 → Isolated testing
Hasilnya:
- Setiap PR punya database sendiri
- Cleanup otomatis saat PR di-merge/ditutup
- Production database tetap bersih
Cara Kerja Database Branching#
Neon menggunakan copy-on-write untuk branching:
main branch (production data)
│
├── pr-123 branch (copy data saat branching)
│ └── Developer A bisa modify tanpa ngaruh main
│
├── pr-124 branch (copy data saat branching)
│ └── Developer B bisa modify tanpa ngaruh main
│
└── staging branch (copy data dari main)
└── QA testing tanpa ngaruh production
Yang bikin Neon spesial:
- Branch instan (milidetik, bukan menit)
- Storage efisien (cuma simpan perbedaan)
- Scale to zero (branch idle = ga bayar)
Setup CI/CD dengan Database Branching#
Langkah 1: Setup Neon + Helipod#
- Connect Neon ke Helipod (lihat tutorial integrasi)
- Aktifkan Branch per environment
- Catat naming pattern yang dipakai
Langkah 2: Konfigurasi GitHub Actions#
Buat file .github/workflows/preview.yml:
name: Preview Environment
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Neon Branch
run: |
# Buat branch database untuk PR ini
BRANCH_NAME="pr-${{ github.event.pull_request.number }}"
curl -X POST "https://console.neon.tech/api/v2/projects/{project_id}/branches" \
-H "Authorization: Bearer ${{ secrets.NEON_API_KEY }}" \
-H "Content-Type: application/json" \
-d "{\"branch\": {\"parent_id\": \"main\"}, \"name\": \"$BRANCH_NAME\"}"
env:
NEON_API_KEY: ${{ secrets.NEON_API_KEY }}
- name: Deploy to Helipod
run: |
# Deploy dengan branch database baru
helipod deploy \
--branch ${{ github.event.pull_request.number }} \
--env DATABASE_URL="postgresql://..."
Langkah 3: Cleanup Otomatis#
Buat file .github/workflows/cleanup.yml:
name: Cleanup Preview
on:
pull_request:
types: [closed]
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete Neon Branch
run: |
BRANCH_NAME="pr-${{ github.event.pull_request.number }}"
curl -X DELETE "https://console.neon.tech/api/v2/projects/{project_id}/branches/{branch_id}" \
-H "Authorization: Bearer ${{ secrets.NEON_API_KEY }}"
env:
NEON_API_KEY: ${{ secrets.NEON_API_KEY }}
Real Use Cases#
Use Case 1: Feature Development#
Situasi: Developer sedang buat fitur baru yang butuh schema changes
# 1. Buat branch dari main
git checkout -b feature/new-payment
# 2. Helipod otomatis buat database branch
# Database branch: feature-new-payment
# 3. Jalankan migration
npx prisma migrate dev
# 4. Push kode
git push origin feature/new-payment
# 5. PR dibuat → Database branch siap untuk testing
Use Case 2: Pull Request Testing#
Situasi: QA perlu test PR sebelum di-merge
PR #123: Add payment feature
├── Code branch: feature/payment
├── Database branch: pr-123
├── Preview URL: https://pr-123.helipod.app
└── Database: Isolated, safe for testing
Use Case 3: Hotfix Production#
Situasi: Bug production, perlu fix sekarang
# 1. Buat hotfix branch
git checkout -b hotfix/critical-bug
# 2. Database branch otomatis dibuat
# Tapi ini dari production data!
# 3. Fix bug
# 4. Test di database branch
# 5. Merge ke main → Auto-deploy ke production
Best Practices#
1. Naming Pattern yang Konsisten#
# Gunakan pattern yang jelas
pr-{number} → Pull request branches
staging → Staging environment
feature-{name} → Feature branches
hotfix-{name} → Hotfix branches
2. Limit Branch Count#
# Neon free tier: max 10 branches
# Neon pro: max 100 branches
# Pastikan cleanup otomatis jalan
# Delete branch saat PR closed/merged
3. Connection Pooling untuk Branches#
# Setiap branch butuh connection pooling
DATABASE_URL="postgresql://...@ep-xxx-pooler.region.neon.tech/dbname?pgbouncer=true"
4. Monitoring#
# Monitor branch usage
# Di Helipod dashboard: Settings → Integrations → Neon
# Lihat jumlah branches dan storage usage
FAQ#
Berapa biaya Neon untuk CI/CD?#
Neon free tier mendukung 10 branches dengan 512MB storage. Untuk kebutuhan CI/CD yang lebih besar, Neon Pro tersedia mulai $19/bulan.
Apakah database branch otomatis cleanup?#
Ya! Di Helipod, kamu bisa setup cleanup otomatis saat environment dihapus. Untuk GitHub Actions, tambahkan workflow cleanup seperti yang dijelaskan di atas.
Bagaimana jika butuh production data di branch?#
Kamu bisa clone production branch ke feature branch. Data akan di-copy secara instan tanpa downtime.
Bisakah saya pindah dari Supabase/Other ke Neon?#
Ya! Lihat tutorial migrasi database ke serverless PostgreSQL.
Checklist Setup CI/CD#
- Setup Neon + Helipod
- Konfigurasi GitHub Actions workflow
- Setup cleanup workflow
- Test dengan PR pertama
- Monitor branch usage
Kesimpulan#
Database branching untuk CI/CD bukan lagi fitur "nice to have", ini sudah jadi kebutuhan untuk tim development yang serius. Dengan Neon + Helipod, kamu bisa dapat:
- ✅ Database branch otomatis untuk setiap PR
- ✅ Cleanup otomatis saat PR di-merge
- ✅ Isolasi sempurna antar PR
- ✅ Zero-config setup
Butuh bantuan setup? Hubungi support@helipod.io
Baca juga: