Migration Guide
This guide covers strategies for migrating between versions of Zero, upgrading dependencies, and evolving your application’s schema and queries.Version Migration Strategy
Semantic Versioning
Zero follows semantic versioning (semver):- Patch releases (0.0.x): Bug fixes, no breaking changes
- Minor releases (0.x.0): New features, backward compatible
- Major releases (x.0.0): Breaking changes, migration required
Upgrade Process
- Review release notes for breaking changes and new features
- Test in development environment first
- Update dependencies across all packages
- Run type checking to catch API changes
- Test queries and mutations thoroughly
- Deploy incrementally (canary or staged rollout)
Monorepo Coordination
Zero is developed in a monorepo with multiple packages. When upgrading:Schema Migration
Adding Tables
Adding new tables is backward compatible:- Add table to schema definition
- Create database migration (PostgreSQL)
- Deploy server first (server can handle old and new schemas)
- Deploy client update
Adding Columns
Adding optional columns is backward compatible:Making Columns Required
Requires two-phase migration: Phase 1: Add optional columnRemoving Columns
Requires two-phase migration: Phase 1: Make column optionalRenaming Columns
Renaming is a breaking change. Use a two-phase migration: Phase 1: Add new column, keep oldChanging Column Types
Type changes are complex and risky. Recommended approach: Option 1: Add new column (safest)Query Migration
Updating Query API Usage
When Zero’s query API changes: Before (hypothetical old API):- Search codebase for old API usage
- Update incrementally, testing each change
- Use TypeScript to catch incompatibilities
Migrating Complex Queries
If query semantics change between versions: Strategy 1: Side-by-side comparisonMutation Migration
Updating Mutation Signatures
When mutation APIs change: Before:- Update all call sites
- Use TypeScript to find incompatible calls
- Test thoroughly (mutations modify data!)
Custom Mutation Evolution
When evolving custom mutations: Backward-compatible approach:Data Migrations
For complex data transformations:- Run migrations in off-peak hours
- Process in batches to avoid timeouts
- Add progress logging
- Make migrations idempotent (safe to re-run)
- Test on copy of production data first
Dependency Updates
Updating Replicache
Zero uses Replicache internally. When Replicache updates:- Check Zero release notes for compatibility
- Test sync behavior thoroughly
- Verify IndexedDB schema migrations
Updating Database Driver
When updating PostgreSQL driver:- Connection pooling behavior
- Query performance
- Transaction handling
- Error handling
Updating TypeScript
Zero uses TypeScript ~5.9.3:- Stricter type checking may reveal hidden bugs
- Update type definitions (
@types/*) - Fix new errors before deploying
Development Environment Migration
Updating Local Database
When schema changes require database updates:Clearing Client State
Sometimes breaking changes require clearing client state:- Schema structure changes significantly
- Data format changes
- Persistent errors after update
Production Migration
Zero-Downtime Deployment
Strategy 1: Backward-compatible changes- Deploy server with new schema (supports old and new)
- Deploy client update
- Remove old code in next release
- Run database migration (add columns, indexes)
- Deploy server update
- Deploy client update
- Clean up deprecated code
- Set up parallel environment with new version
- Route subset of traffic to new environment
- Monitor for issues
- Gradually shift traffic
- Shut down old environment
Rollback Strategy
Always have a rollback plan: Application rollback:- Restore from backup (last resort)
- Use point-in-time recovery if available
- Test restore process regularly
Monitoring Migration
Track metrics during migration:- Error rates
- Query performance
- Sync latency
- Memory usage
- User-reported issues
Testing Migrations
Test Checklist
- Schema changes applied to test database
- All queries return expected results
- All mutations work correctly
- No TypeScript errors
- No runtime errors in console
- Performance metrics acceptable
- Sync works correctly (online/offline)
- Data integrity maintained
- Rollback tested successfully
Automated Tests
Manual Testing
- Test in isolation: Fresh database, apply migrations, verify schema
- Test with production data: Copy production DB, test migration
- Test rollback: Apply migration, then rollback, verify state
- Test upgrade path: Migrate from each previous version
Common Migration Patterns
Adding Indexes
Safe to do anytime:- Improves query performance
- No application code changes needed
- Zero downtime
Splitting Tables
Complex migration requiring multiple steps:- Create new tables
- Dual-write to old and new tables
- Backfill historical data
- Switch reads to new tables
- Remove dual-write logic
- Drop old tables
Merging Tables
Similar to splitting, in reverse:- Create merged table
- Dual-write to old tables and new table
- Backfill historical data
- Switch reads to new table
- Remove dual-write logic
- Drop old tables
Version-Specific Guides
Future Migrations
As Zero evolves, version-specific migration guides will be added here. Check release notes for:- Breaking changes
- Deprecated APIs
- New features
- Performance improvements
- Security updates
Best Practices
- Always test migrations in development first
- Use semantic versioning to communicate changes
- Keep backward compatibility when possible
- Document breaking changes clearly
- Provide migration scripts for complex changes
- Monitor production during and after migration
- Have rollback plan ready
- Communicate with team about migration timeline
- Update dependencies together (don’t mix versions)
- Run ANALYZE after schema changes
Resources
- Release Notes: Check GitHub releases for each version
- Monorepo: https://github.com/rocicorp/mono
- Documentation: https://zero.rocicorp.dev
- Discord: https://discord.gg/rocicorp
Next Steps
- Review Performance optimization techniques
- Learn about ZQL Engine internals
- Debug issues using Troubleshooting guide