CI/CD Integration
Automate database operations in your CI/CD pipeline.
Overview
Integrate Postbase into your pipeline:
- Run migrations
- Generate types
- Run tests
- Deploy
GitHub Actions
Basic Setup
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Install Postbase CLI
run: npm install -g postbase
- name: Run migrations
env:
POSTBASE_TOKEN: ${{ secrets.POSTBASE_TOKEN }}
run: |
postbase cloud migrate up \
-p my-project \
-d production
- name: Deploy application
run: npm run deployFull Pipeline
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
POSTBASE_TOKEN: ${{ secrets.POSTBASE_TOKEN }}
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: supabase/postgres:15.14.1.072
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Install Postbase CLI
run: npm install -g postbase
- name: Run migrations (local)
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
run: postbase migrate up
- name: Generate types
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
run: postbase types generate --output ./src/db/types.ts --all
- name: Check types match
run: |
git diff --exit-code src/db/types.ts || \
(echo "Types out of date! Run 'postbase types generate'" && exit 1)
- name: Run tests
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
run: npm test
deploy-staging:
needs: test
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Postbase CLI
run: npm install -g postbase
- name: Run migrations (staging)
run: |
postbase cloud migrate up \
-p my-project \
-d staging
- name: Deploy to staging
run: npm run deploy:staging
deploy-production:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Postbase CLI
run: npm install -g postbase
- name: Create backup
run: |
postbase cloud backups create \
-p my-project \
-d production
- name: Run migrations (production)
run: |
postbase cloud migrate up \
-p my-project \
-d production
- name: Deploy to production
run: npm run deploy:productionGitLab CI
# .gitlab-ci.yml
stages:
- test
- deploy
variables:
POSTGRES_PASSWORD: postgres
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/postgres
test:
stage: test
image: node:22
services:
- name: supabase/postgres:15.14.1.072
alias: postgres
script:
- npm ci
- npm install -g postbase
- postbase migrate up
- npm test
deploy:
stage: deploy
image: node:22
only:
- main
script:
- npm ci
- npm install -g postbase
- postbase cloud migrate up -p my-project -d production
- npm run deploy
environment:
name: productionCircleCI
# .circleci/config.yml
version: 2.1
jobs:
test:
docker:
- image: node:22
- image: supabase/postgres:15.14.1.072
environment:
POSTGRES_PASSWORD: postgres
steps:
- checkout
- run: npm ci
- run: npm install -g postbase
- run:
name: Wait for Postgres
command: |
for i in {1..30}; do
pg_isready -h localhost -p 5432 && break
sleep 1
done
- run:
name: Run migrations
environment:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
command: postbase migrate up
- run: npm test
deploy:
docker:
- image: node:22
steps:
- checkout
- run: npm ci
- run: npm install -g postbase
- run:
name: Deploy migrations
command: |
postbase cloud migrate up \
-p my-project \
-d production
- run: npm run deploy
workflows:
build-and-deploy:
jobs:
- test
- deploy:
requires:
- test
filters:
branches:
only: mainBest Practices
1. Pre-Deployment Backups
Always backup before migrations:
- name: Create backup
run: postbase cloud backups create -p $PROJECT -d production2. Migration Dry Run
Test migrations before applying:
- name: Dry run migrations
run: postbase migrate up --dry-run3. Type Checking
Verify generated types match:
- name: Check types
run: |
postbase types generate --output ./src/db/types.ts
git diff --exit-code src/db/types.ts4. Rollback Strategy
Have rollback ready:
- name: Rollback on failure
if: failure()
run: |
postbase migrate down
# Or restore from backup
postbase cloud backups restore $BACKUP_ID -p $PROJECT -d production5. Environment Isolation
Use separate databases per environment:
deploy-staging:
environment: staging
env:
DATABASE: staging
deploy-production:
environment: production
env:
DATABASE: productionSecrets Management
GitHub
# Set secrets
gh secret set POSTBASE_TOKEN --body "pb_xxx..."
gh secret set DATABASE_URL --body "postgresql://..."GitLab
Settings → CI/CD → Variables
CircleCI
Project Settings → Environment Variables
Troubleshooting
Migration Failed
- name: Check migration status
if: failure()
run: postbase migrate statusConnection Issues
- name: Test connection
run: |
psql "$DATABASE_URL" -c "SELECT 1"Token Expired
Regenerate token:
postbase cloud login
# Copy new token to CI secrets