question 489 Application Delivery · hard
The pre-deploy gate
Combine the lesson's pieces into the gate the release script calls before switching traffic: migrate the database, then check the settings and the schema, and decide. Write predeploy(conn, environ, migrations, required_env).
Function
predeploy(conn, environ, migrations, required_env); conn uses isolation_level=NoneStep 1apply pending migrations (each version in its own transaction with its
PRAGMA user_version); if one fails, roll it back and record "migration <v> failed: <error message>", and apply nothing after itStep 2for each name in
required_env that is missing or empty in environ, record "missing setting <NAME>"Step 3if the schema version isn't the highest version in
migrations, record "schema at <v>, release needs <n>"Returns
{"applied": [...], "problems": [...], "ready": bool} (problems in step order; ready when there are none); nothing is raised