# Database Migration Playbook (MySQL, PostgreSQL, MongoDB)

Date: 2026-03-07
Scope: GCP to LotusCloud with low-downtime cutover.

## Objective

- Provide a repeatable migration workflow for assessment, rehearsal, cutover, and rollback.
- Reduce risk for production migration with strict validation checkpoints.

## Standard Migration Phases

1. Assessment
- Inventory source DB version, size, QPS, peak windows, replication topology.
- Classify workload: OLTP, analytics, mixed.
- Define downtime target and RTO/RPO.

2. Dry Run (Rehearsal)
- Restore latest backup to staging target.
- Run schema compatibility checks.
- Run data consistency checks (row count, checksums, sampled queries).
- Run application smoke tests against staging target.

3. Continuous Sync / CDC
- Enable incremental replication from source to target.
- Monitor replication lag and error rate.
- Freeze high-risk schema changes during final migration window.

4. Cutover
- Put app in maintenance mode or write-throttle mode.
- Wait replication lag reaches target threshold.
- Switch app connection strings to LotusCloud target.
- Perform immediate post-cutover health checks.

5. Rollback
- Pre-define rollback trigger conditions.
- Keep source writable fallback path during early stabilization.
- Revert DNS/config and replay buffered writes if required.

## Engine-Specific Notes

### MySQL
- Recommended tools: `mysqldump` (small/medium), physical backup for large datasets.
- CDC option: binlog-based replication.
- Validate collation/charset and timezone consistency.

### PostgreSQL
- Recommended tools: `pg_dump` (logical), `pg_basebackup` (physical).
- CDC option: logical replication or WAL-based tooling.
- Validate extension compatibility before cutover.

### MongoDB
- Recommended tools: `mongodump/mongorestore` for rehearsal.
- CDC option: oplog tailing strategy.
- Validate index build time and write amplification impact.

## Verification Checklist

- Schema migration completed with zero blocking errors.
- Row/document counts match within defined tolerance.
- Business-critical query latency baseline within agreed threshold.
- Authentication and network policy validated from application side.
- Backup and restore test completed on target.

## Deliverables for Each Migration

- Migration design note.
- Rehearsal report.
- Cutover runbook with timeline and owner matrix.
- Rollback runbook and decision gates.
- Post-cutover validation report.
