Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Dry-Run Database Migrations on a Clone to Prevent Data Loss

Описание и применение

Стандартные тесты не видят потери данных во время миграции БД. Рекомендуется запускать 'сухой прогон' на клоне продакшн-схемы с выборкой данных, проверяя как прямую, так и обратную миграцию через сравнение снимков метрик (количество строк, null-значения, ограничения).

Задача

Standard test suites validate the post-migration schema but cannot detect data loss or corruption that occurs during the migration process, especially when AI-generated migrations are used. Staging environments often lack representative data, making them poor substitutes for verifying migration safety.

Результат

The workflow provides a mechanical verification method to ensure database migrations are reversible and do not cause silent data loss. It shifts the focus from 'does the app work with the new schema?' to 'can we safely revert if something goes wrong?'

Рабочий процесс

  • Clone the production schema and load a representative data sample (e.g., a few thousand rows per table).
  • Snapshot the baseline metrics: record row counts, null rates, and constraint counts before any migration.
  • Apply the 'up' migration and snapshot the metrics again.
  • Apply the 'down' migration and snapshot the metrics a third time.
  • Compare all three snapshots to ensure the 'up' migration changes only intended fields and the 'down' migration restores the baseline exactly.

Доказательства

A green test suite is the wrong tool for judging an AI-generated migration, because tests run against the post-migration schema and never observe the intermediate states where data disappears.

Источник

The key property is not that the down migration executes without error; it is that the schema and data return to the baseline state.

Источник

  • Дата записи: 2026-09-05T12:47:43.507Z