ბაზები6 წუთის საკითხავი
Schema migrations without downtime
Adding is safe, removing is safe later, and renaming is what breaks things. The expand-and-contract pattern, in the order it actually works.
ეს სტატია ჯერ ინგლისურადაა. ვთარგმნით.
During any deploy there is a window where old and new code are both running against one database. Every safe migration follows from that fact, and every unsafe one ignores it.
Expand, migrate, contract
- Expand: add the new column or table. Old code ignores it; new code can use it.
- Deploy the code that writes to both the old and the new shape.
- Backfill the existing rows, in batches, while everything keeps running.
- Deploy the code that reads only the new shape.
- Contract: drop the old column, in a later release, once nothing refers to it.
The operations to be careful with
- Renaming a column: never in one step. It is add, backfill, switch, drop.
- Adding a NOT NULL column without a default, which rewrites the table.
- Creating an index on a large table without the concurrent option, which locks writes.
Five boring deploys are cheaper than one interesting one.