Database
The state store is a database the API creates itself: a SQLite file, or
PostgreSQL when API_DATABASE_URL is set. At startup on PostgreSQL, the API
copies the rows of an existing SQLite file into PostgreSQL one time, only while
the PostgreSQL tables are empty. The schema is in the Alembic revisions of
state_migrations/versions. state.py brings the database to the last revision
on each SQLite connection, or one time for each PostgreSQL connection pool, and
it refuses a database at a revision that the release does not know. A deployment row is the operator's last submitted configuration; a
build row is one run of the deployment machinery against it, and a deployment's
state is derived from its build history rather than stored. The db-diagram
package opens a throwaway database through state.py and reads the schema back
out of it, so the picture below shows what the API creates at the revision that
built this page: