برنامهریز مهاجرت بدون توقف دیتابیس
Why this prompt matters
Schema migrations are the #1 cause of production outages. Planning backward-compatible phases eliminates the 'big bang' migration risk.
What we use it for
Database management
Prompt
Plan a zero-downtime database migration for the described schema change. Include: 1) Step-by-step migration phases, 2) Backward-compatible intermediate states, 3) Data backfill strategy, 4) Rollback plan for each phase, 5) Monitoring queries to verify data integrity, 6) Estimated timeline.
Result
## Migration Plan: Adding `organization_id` to Users
### Phase 1: Add Column (Deploy anytime) ```sql ALTER TABLE users ADD COLUMN organization_id UUID; CREATE INDEX CONCURRENTLY idx_users_org ON users(organization_id); ``` Application continues to work — column is nullable.
### Phase 2: Backfill (Run in batches) ```sql UPDATE users SET organization_id = (SELECT id FROM organizations WHERE ...) WHERE organization_id IS NULL LIMIT 1000; ```
### Phase 3: Make Required (After backfill verified) ```sql ALTER TABLE users ALTER COLUMN organization_id SET NOT NULL; ```
**Rollback**: Each phase is independently reversible.
Schema migrations are the #1 cause of production outages. Planning backward-compatible phases eliminates the 'big bang' migration risk.
This prompt demonstrates a structured approach to database management, producing consistent, high-quality results that can be iterated upon.