๐—ง๐—ฒ๐˜€๐˜๐—ถ๐—ป๐—ด ๐——๐—ฎ๐˜๐—ฎ๐—ฏ๐—ฎ๐˜€๐—ฒ ๐— ๐—ถ๐—ด๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—ช๐—ถ๐˜๐—ต ๐—ฆ๐—ต๐—ฎ๐—ฑ๐—ผ๐˜„ ๐—ฆ๐—ฐ๐—ต๐—ฒ๐—บ๐—ฎ๐˜€

Database migrations risk production. Code looks right. It fails on real data. A shadow schema solves this.

A shadow schema is a separate environment. It mirrors production. It reveals issues unit tests miss.

Use a three phase process.

Do this in CI with a disposable container. For large systems, make it a pipeline stage.

A good test suite checks more than the script run. Verify these points.

Do not only run SQL. Encode expectations your application needs.

Large tables lock rows. This slows your app. Use batch updates. Update in chunks of 10,000 rows. This is safer at scale.

Automate the process. Add a pipeline job.

Fail the build if the migration fails. This makes safety a requirement.

Before shipping, confirm these five things.

Shadow schema testing gives you a controlled place to prove your work. It catches structural and operational failures.

Make your deployments boring.

Source: https://dev.to/therizwansaleem/testing-database-migrations-safely-with-a-shadow-schema-1mmb