Essayer gratuitement
4 min lecture Guide 373 of 877

How to Manage Database Migrations in Development Projects?

How to manage database migrations in development projects?

Manage database migrations by creating tasks for each migration with clear sequencing labels, documenting rollback procedures in task descriptions, and coordinating deployment timing with Team Standup. Use labels for migration status (migration:pending, migration:applied), review migrations in code review column, and keep migration runbooks in NoteVault.

Migration task template

## Migration: Add user_preferences table

Purpose: Store user notification preferences

Migration file: 20250127_add_user_preferences.sql

Changes:
- CREATE TABLE user_preferences
- Add foreign key to users table
- Create indexes for user_id

Dependencies:
- Requires: 20250120_update_users_table (applied)
- Blocks: User preferences feature

Rollback:

DROP TABLE IF EXISTS user_preferences;


Testing:
- [ ] Run in local environment
- [ ] Apply to staging
- [ ] Verify app works with new schema
- [ ] Test rollback procedure

Deployment:
- Window: Tuesday 2am-4am UTC
- Estimated time: 5 minutes
- Downtime: None (additive change)

Migration labels

LabelPurpose
migration:pendingNot yet applied anywhere
migration:stagingApplied to staging
migration:productionApplied to production
migration:breakingRequires app code change
migration:additiveSafe to apply anytime
migration:data-migrationMoves/transforms data

Migration board columns

ColumnPurpose
BacklogPlanned migrations
DevelopmentWriting migration
ReviewCode review + DBA review
StagingApplied to staging
ApprovedReady for production
ProductionApplied and verified

Migration coordination:

  1. Create migration task - Use template above
  2. Add dependencies - What must apply first
  3. Write migration - Development work
  4. Code review - Standard PR process
  5. DBA review - For complex migrations
  6. Apply to staging - Test in staging env
  7. Verify staging - App works correctly
  8. Schedule production - Deployment window
  9. Apply to production - Execute migration
  10. Verify production - Confirm success
  11. Mark complete - Move to Done

NoteVault migration runbook

# Database Migration Runbook

## Pre-Deployment Checklist
- [ ] Migration reviewed and approved
- [ ] Rollback script tested
- [ ] Staging verification complete
- [ ] Dependent teams notified
- [ ] Backup verified

## Deployment Steps
1. Enable maintenance mode (if needed)
2. Take database backup
3. Run migration script
4. Verify migration applied
5. Run smoke tests
6. Disable maintenance mode

## Rollback Procedure
1. Enable maintenance mode
2. Run rollback script
3. Verify rollback complete
4. Disable maintenance mode
5. Notify team of rollback

## Emergency Contacts
- DBA: @dba-oncall
- Platform: @platform-oncall

Common migration patterns

PatternWhen to Use
AdditiveAdding tables, columns
RenameBlue-green with alias
Data migrationBackfill historical data
IndexPerformance improvements
ConstraintAdding foreign keys
BreakingCoordinate with app deploy