Plan a repeatable, reversible data migration | DevPrompt Lab

Preserve legacy rows and prove the migration can safely run again.

prompt · Database · advanced

English Tiếng Việt

Use for schema changes that need deterministic mapping, conflict handling, rollback evidence, and isolated migration tests.

Reusable content

Plan the migration from the supplied old schema to the new one. Define a deterministic mapping for each legacy identity, how duplicates and incomplete rows are handled, transaction boundaries, constraints and indexes, and whether each step is safe to rerun. Preserve source records until verification succeeds. Provide preflight counts, post-migration reconciliation queries, and a rollback procedure. State which DDL commits implicitly for the chosen database engine. Never target production from an automated test.

Database engine: {{DB_ENGINE}}

Old schema: {{OLD_SCHEMA}}

New schema: {{NEW_SCHEMA}}

Legacy data and expected counts: {{RECORDS}}

How to use it

Attach schema definitions and anonymized counts. Identify an independently restorable backup before changing data.

Example

Idempotency: unique legacy_source_id plus INSERT IGNORE. Preservation check: compare grouped source and destination counts by status before enabling canonical reads.