# 19. The database must be ready first

> Code that deploys by itself must never arrive before the tables it expects.

Lesson 19 of 27. Part 3 of 6: Set the boundaries. Source: https://chiefofagents.si/lessons/the-database-must-be-ready-first

## The lesson

New code may expect new tables, columns or permissions. If the code deploys automatically and production does not have them yet, it fails.

So additive database changes are applied and verified before the code that depends on them is merged.

A migration that has been applied is never edited. If it has a defect, a new corrective migration is added. Editing it would make different environments disagree about what the same migration means.

## How I do it

The order is fixed: additive change, verify real behaviour, database ready, then my merge.

## The rule

Database first, code second, and never rewrite a migration that has already run.
