database-package (BTDB001)¶
Added in 0.8.0 · Stable · Enabled by default (warning)
Family: database · Standard: CES-18 · Languages: python
Formerly known as: arch-database-package
Directive¶
Relational persistence lives in its own database package: SQLModel tables, repositories,
migrations and the connection and session setup, together. Not under persistence/, meta/ or
core/. A warning by default.
The rule looks only at the files under **/persistence/**, **/meta/** and **/core/**, and
reports:
| Code | Why it is misplaced |
|---|---|
class X(SQLModel, table=True): |
a table outside the database package |
create_engine(...) |
connection setup outside the database package |
sessionmaker(...) |
a session factory outside the database package |
A correctly placed database/ package, and a repository without a relational layer, are left
alone.
Why¶
- One
databasepackage gives persistence a boundary: a single place owns the schema, the engine and the queries, and the rest of the application depends on an explicit seam. core/andmeta/are cross-cutting homes. A table or an engine in them makescore/depend on the database layer.
Do¶
myapp/
database/
models.py # SQLModel tables
engine.py # create_engine, sessionmaker
repositories.py
migrations/
Don't¶
Suppression¶
A comment on the line where the finding starts silences it: the class line, or the line of the
create_engine(...) or sessionmaker(...) call.