Skip to content

db-no-create-all (BTDB002)

Added in 0.10.0 · Preview · Off by default (warning)

Family: database · Standard: CES-18 · Languages: python

This rule is unstable and in preview. It runs only with preview = true, and only when it is selected.

Directive

metadata.create_all(...) is reported outside the tests: the schema evolves through Alembic migrations only. A warning by default.

Why

create_all builds the tables the models describe today and skips the ones a migration would have changed, so the schema of a database and its migration history drift apart without a trace.

Do

command.upgrade(config, "head")

Don't

SQLModel.metadata.create_all(engine)

Suppression

A comment on the line of the create_all(...) call silences it.

SQLModel.metadata.create_all(engine)  # botica: ignore[db-no-create-all]
SQLModel.metadata.create_all(engine)  # noqa: BTDB002 -- reason

Discussion