Say, you want to change schema A to schema B. Here’s a reference to all the steps you need.
(here’s someone elaborated it: https://kiranrao.ca/2022/05/04/zero-downtime-migrations.html)
-
Create schema B.
-
Write a script to copy data from schema A to schema B. (You will need it later).
Script must be idempotent to run multiple times. -
Copy the data.
-
Change main code to write to schema B.
-
Copy the data again (in case between steps 3. and 4. there were some missing writes).
-
Change main code to read from schema B, but don’t use it yet.
Just compare with what was read from schema A, and monitor the differences. -
Wait for some time to make sure all reads are fine.
-
Switch to using data from schema B (but reading schema A and monitor differences).
-
Wait for M days to make sure users are happy as well, not just your monitoring.
-
Turn off schema A.