Database Branches
PBS Knowledge uses TerminusDB, which supports Git-like branching for data versioning and testing.
Overview
What Are Branches?
Database branches allow:
- Creating snapshots of data
- Testing changes without affecting production
- Rolling back to previous states
- Parallel development of features
Branch Structure
main (production)
├── test (testing environment)
├── feature-x (feature development)
└── backup-2024-01-15 (point-in-time backup)
Current Setup
Main Branch
The main branch:
- Contains production data
- Is used by all regular operations
- Should never be deleted
- Changes tracked automatically
Other Branches
Additional branches may exist for:
- Testing new features
- Development environments
- Point-in-time backups
- Data migration staging
Working with Branches
Viewing Branches
- Go to Admin → System → Database
- See all branches
- View branch status
- Check current active branch
Creating a Branch
caution
Branch creation requires careful consideration of data size and system resources.
- Go to Admin → Database → Branches
- Click Create Branch
- Enter:
- Branch name
- Source branch (usually main)
- Description
- Create branch
Switching Branches
For testing or development:
- Set
TERMINUSDB_BRANCHenvironment variable - Restart the application
- Application uses specified branch
warning
Never switch production to a non-main branch without careful planning.
Branch Operations
Merge
Merge changes from one branch to another:
- Select source branch
- Select target branch
- Preview changes
- Resolve conflicts if any
- Execute merge
Diff
Compare branches:
- Select two branches
- View differences
- See added/modified/deleted documents
- Export diff report
Delete
Remove a branch:
- Select branch to delete
- Confirm deletion
- Branch and all data are removed
danger
Deleted branches cannot be recovered. Always ensure data is backed up or merged before deletion.
Use Cases
Testing Schema Changes
Before applying schema changes:
- Create test branch from main
- Apply schema changes to test branch
- Validate changes work correctly
- Merge to main if successful
- Delete test branch
Data Migration
For major data migrations:
- Create migration branch
- Run migration scripts
- Validate data integrity
- Switch production to new branch
- Keep old branch as backup
Development Environment
For development:
- Create dev branch periodically
- Developers work against dev branch
- Test changes safely
- Never affects production
Backup Integration
Branch Backups
Branches can serve as backups:
- Create dated branch (e.g.,
backup-2024-01-15) - Provides point-in-time snapshot
- Can restore by merging back
- More flexible than file backups
Automated Backups
Configure automatic branch creation:
- Set backup schedule
- Define retention policy
- Old backup branches auto-deleted
- Most recent backups preserved
Best Practices
Branch Naming
Use clear, consistent naming:
test-{feature}for testingbackup-{date}for backupsdev-{username}for development- Avoid special characters
Branch Lifecycle
- Create with clear purpose
- Document the branch
- Delete when no longer needed
- Don't let branches accumulate
Data Integrity
- Always test merges carefully
- Back up before major operations
- Validate after branch operations
- Monitor disk usage
Troubleshooting
Branch Creation Failed
- Check available disk space
- Verify user permissions
- Check database connectivity
- Review error logs
Merge Conflicts
- Review conflicting documents
- Decide which version to keep
- Manually resolve if needed
- Document resolution decisions
Performance Issues
If branches cause slowdowns:
- Limit number of active branches
- Delete unused branches
- Monitor database size
- Consider compaction
Limitations
Current Limitations
In TerminusDB v11.2:
- Branch creation can be slow for large databases
- Some operations require exclusive access
- Merge conflict resolution is limited
Recommendations
- Keep branch count low
- Use branches for specific purposes
- Prefer main branch for normal operations
- Test branch operations in development first