Team Collaboration
When multiple developers work on the same database schema, coordination is essential. This guide covers best practices for team-based schema management with pgtofu.Version Control Strategy
Repository Structure
.gitignore
Branch Strategy
Handling Merge Conflicts
Schema File Conflicts
Schema files rarely conflict because they’re declarative. If two developers modify the same table: Developer A adds a column:Migration File Conflicts
Migration files can conflict on version numbers. Resolution:- Keep both migration sets
- Renumber the later one
- Regenerate from merged schema to verify
Workflow for Team Development
Starting a Feature
Making Changes
Before Creating PR
Code Review Checklist
For schema PRs, reviewers should check:- Schema changes are intentional and complete
- Generated migrations are correct
- No breaking changes without explicit approval
- Indexes added for foreign keys and frequently queried columns
- Constraints properly named
- Down migrations are valid
Coordination Strategies
Shared Development Database
All developers use the same development database: Pros:- Always have the “current” state
- No local database setup needed
- Migrations can conflict
- One developer’s changes affect others
Individual Development Databases
Each developer has their own database: Pros:- Isolation during development
- Can experiment freely
- Must keep databases in sync
- Harder to reproduce issues
Hybrid Approach
- Individual databases for feature development
- Shared staging database for integration testing
Communication Patterns
Announcing Breaking Changes
When making breaking changes, communicate early:Schema Change Log
Maintain a CHANGELOG for significant changes:Handling Long-Running Migrations
Feature Flags for Schema Changes
For changes that affect application code:- Phase 1: Add new column/table (migration)
- Phase 2: Deploy code that writes to both old and new
- Phase 3: Migrate data (background job)
- Phase 4: Deploy code that reads from new
- Phase 5: Remove old column/table (migration)
Example: Renaming a Column
Troubleshooting Team Issues
Migration version conflicts
Migration version conflicts
Two developers created migrations with the same version number.Solution: Renumber the later migration and regenerate to verify correctness.
Schema drift
Schema drift
Production schema doesn’t match expected state.Solution:
- Extract production schema
- Diff against desired schema
- Generate corrective migrations
- Review and apply
Conflicting changes
Conflicting changes
Two features modify the same table incompatibly.Solution:
- Coordinate on final schema design
- Merge schema files first
- Regenerate migrations from merged schema
CI failures on schema check
CI failures on schema check
CI reports schema differences that shouldn’t exist.Solution:
- Ensure CI database matches expected state
- Apply all pending migrations before checking
- Verify no manual changes were made to CI database
Best Practices Summary
Communication
Communication
- Announce breaking changes in advance
- Use PR descriptions to explain schema changes
- Maintain a schema changelog
Coordination
Coordination
- Keep feature branches short-lived
- Rebase frequently on main
- Regenerate migrations after rebasing
Review
Review
- Review both schema files and generated migrations
- Check for breaking changes
- Verify down migrations work
Testing
Testing
- Test migrations on copy of production data
- Use staging environment before production
- Monitor migration performance
See Also
- Basic Workflow - Individual developer workflow
- CI/CD Integration - Automated pipelines
- Schema Diffing - How changes are detected