Skip to content

Startup runs create_all(), which permanently hides schema drift from Alembic #34

Description

@lovebear2008

The lifespan hook calls init_db() on every boot:

        from app.db.engine import init_db

        init_db()
        logger.info("Database initialized/verified on startup")

backend/app/main.py:30

and init_db is metadata.create_all (backend/app/db/engine.py:93), whose own docstring says "In production, use Alembic migrations instead" (backend/app/db/engine.py:80).

create_all is create-if-missing only. It never alters an existing table.

Trigger: add a nullable column to CodeJob, restart the server against an existing app.db.
Observed: startup logs "Database tables created/verified", the app boots green, and the first SELECT that touches the new column fails at request time with no such column. get_migration_status (backend/app/db/engine.py:109) cannot detect this either — it only checks that alembic_version has a row.
Expected: either run alembic upgrade head at startup, or keep create_all strictly behind a FAROS_DEV_AUTOCREATE=1 flag and let a missing table be a loud failure.

The initialized_no_migrations status value at backend/app/db/engine.py:155 shows this ambiguity was already anticipated; it should be treated as an error state rather than a reported-and-ignored one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions