Write a batched, rerunnable data migration from one database to another, with schema mapping, dry run, reconciliation checks, cutover and rollback steps.
Write a data migration from the source database to the target database described below. The script must be safe to rerun, report what it changed, and prove completeness with reconciliation checks. It is a migration plan plus code, not a guarantee of zero downtime. ## Inputs Source system, version and relevant schema (DDL or collection samples): [SOURCE] Target system, version and desired data model: [TARGET] Data volume (rows/documents per table) and change rate during migration: [VOLUME] Allowed downtime or read-only window: [DOWNTIME_WINDOW] Language and libraries available for the script: [LANGUAGE] Transformation rules (type conversions, renames, embedding vs referencing, dropped fields): [MAPPING_RULES] ## Instructions 1. Produce a mapping table from each source field to its target field, type and transformation. Flag lossy conversions (precision, time zones, encodings, NULL vs missing). 2. For a relational-to-document move, justify each embed-versus-reference decision using the access patterns in [TARGET]. 3. Migrate in batches ordered by a stable key, with a checkpoint so an interrupted run resumes instead of duplicating data. Writes must be idempotent (upsert by source primary key). 4. Collect rejected records with the reason instead of stopping silently or dropping them. 5. Support a dry-run mode that transforms and validates without writing. 6. Reconcile after migration: counts per entity, sums or checksums of numeric fields, and a sample of records compared field by field. 7. Describe cutover for [DOWNTIME_WINDOW]: freeze or dual-write, final delta sync, switch, verification. 8. Describe rollback: what is reverted, and whether the source stays authoritative until verification passes. ## Return 1. Header comment: purpose, source, target, assumptions. 2. Mapping table. 3. Script sections: connect and read, transform, create target schema/indexes, batched load with checkpoint, rejected-record log, reconciliation. 4. Cutover and rollback runbook. 5. Known risks and items to test on a copy of production data. ## Acceptance checks - Rerunning the script after a partial run produces no duplicates. - Every source field is mapped, transformed or listed as intentionally dropped. - Reconciliation compares counts and at least one numeric aggregate per entity. - No credentials are hard-coded; connection settings come from environment variables. - The script is described as untested until run against a staging copy.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Source: MySQL 8.0 tables customers(customer_id PK, name, email, created_at DATETIME) and orders(order_id PK, customer_id FK, order_date DATE, total DECIMAL(10,2)) Target: MongoDB 7 collection customers; orders read together with their customer in the account page, but order history may grow past a few thousand per customer for wholesale accounts Volume: 2M customers, 30M orders; about 50 new orders per minute Downtime: 15-minute read-only window allowed Language: Python 3.12 with mysql-connector and pymongo Mapping: store money as integer cents; convert created_at from server local time (Europe/Berlin) to UTC
A plan that keeps orders in a separate collection referenced by customer_id (because unbounded per-customer order counts make embedding risky) with an index on {customer_id, order_date}; total converted to integer total_cents; created_at converted from Europe/Berlin to UTC; batched upserts keyed on source primary keys with a checkpoint file; a rejected-records collection; dry-run flag; reconciliation of counts and SUM(total_cents) per entity; a cutover that backfills before the window and runs a final delta during the 15-minute read-only window; and rollback that keeps MySQL authoritative until checks pass. Illustrative expectation, not a recorded model run.Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts: