A powerful tool for creating and managing PostgreSQL database branches using copy-on-write functionality via database templates. Perfect for GitOps workflows, PR environments, and development/testing isolation.
- ⚡ Instant Branching: Use PostgreSQL's
CREATE DATABASE ... WITH TEMPLATEfor true copy-on-write branching - 🔧 CLI Tool: Easy-to-use command-line interface for all operations
- 🌐 REST API: HTTP API for integration with CI/CD pipelines
- 🐳 Docker Ready: Containerized deployment with Docker Compose
- 🔒 Secure: API key authentication for production environments
- 📊 Monitoring: Branch listing with size and connection information
- 🧹 Auto Cleanup: Automated cleanup of old/unused branches
# Install globally via npm
npm install -g @chad3814/postgres-branch-manager
# Or use via npx
npx @chad3814/postgres-branch-manager --help# Set your database URL
export DATABASE_URL="postgresql://user:pass@localhost:5432/production_db"
# Create a new branch
pg-branch create my-feature --source production_db
# List all branches
pg-branch list
# Check if a branch exists
pg-branch exists my-feature
# Delete a branch
pg-branch delete my-feature
# Clean up old branches
pg-branch cleanup --dry-run# Start the API server
npm start
# Or with Docker
docker-compose upGET /api/branches- List all branchesPOST /api/branches- Create a new branchDELETE /api/branches/:name- Delete a branchGET /api/branches/:name/exists- Check if branch existsPOST /api/branches/cleanup- Cleanup old branches
# Required
DATABASE_URL="postgresql://user:pass@localhost:5432/production_db"
# Optional
DB_PREFIX="branch_" # Default prefix for branch names
PORT=3001 # API server port
NODE_ENV="production" # Environment mode
BRANCH_MANAGEMENT_API_KEY="secret" # API authentication key
SOURCE_DATABASE="production_db" # Default source database- name: Setup Branch Manager
run: |
npm install -g @chad3814/postgres-branch-manager
- name: Create PR Database
run: |
pg-branch create pr-${{ github.event.number }} \
--source production \
--url "${{ secrets.DATABASE_URL }}" \
--verboseversion: '3.8'
services:
branch-manager:
image: ghcr.io/chad3814/postgres-branch-manager:latest
ports:
- "3001:3001"
environment:
- DATABASE_URL=${DATABASE_URL}
- BRANCH_MANAGEMENT_API_KEY=${API_KEY}- Template-Based Branching: Uses PostgreSQL's native
CREATE DATABASE ... WITH TEMPLATEcommand - Copy-on-Write: New branches share data pages with the source until modifications occur
- Instant Creation: Large databases can be branched in seconds
- True Isolation: Each branch is a completely separate database
- Efficient Storage: Only modified pages consume additional space
- Feature Branches: Create isolated databases for feature development
- Testing: Run tests against production-like data without risk
- Experimentation: Try schema changes safely
- PR Environments: Automatic database creation for pull requests
- Staging Deployments: Quick staging environment setup
- Migration Testing: Test database migrations on real data
- Backup/Restore: Create point-in-time snapshots
- Data Analysis: Work with production data copies
- Training: Provide isolated environments for training
curl -X POST http://localhost:3001/api/branches \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key" \
-d '{"name": "feature-branch", "sourceDatabase": "production"}'curl http://localhost:3001/api/branches \
-H "x-api-key: your-api-key"curl -X DELETE http://localhost:3001/api/branches/feature-branch \
-H "x-api-key: your-api-key"# Clone the repository
git clone https://github.com/chad3814/postgres-branch-manager.git
cd postgres-branch-manager
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build for production
npm run build
# Run tests
npm test- PostgreSQL 10+
- Node.js 18+
- Sufficient disk space for branched databases
- Use strong API keys in production
- Limit network access to the API server
- Monitor disk space usage
- Regular cleanup of unused branches
- Secure your PostgreSQL credentials
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details.
- 📖 Documentation
- 🐛 Issues
- 💬 Discussions