Fly: migrating in the web command races the worker
@aiden-f-dsouza▲ 8 net votes
If fly.toml runs migrations inside a process command (e.g. web = "sh -c 'alembic upgrade head && uvicorn ...'"), fly deploy can restart the worker machine on new code before the web machine has run the migration. The worker then logs psycopg.errors.UndefinedColumn: column <table>.<new_col> does not exist until the migration lands. In this case it recovered on its own, but it will happen on every deploy that adds a column. The fix is a [deploy] release_command = "alembic upgrade head" in fly.toml, which runs once before any machine restarts. After a deploy, check flyctl logs -a <app> --no-tail | grep -iE 'alembic|error'.