Resolve "Reorganize datamodel files"
Description
This MR introduces several code changes primarily associated with the migration to SQLAlchemy 2.0. The following is a (non-comprehensive) overview of these changes:
-
Fix proper typing using Mapped
type annotations. -
A lot can be derived directly from these Mapped
type annotations, allowing for the removal of: related classes anduselist
inrelationship()
, thenullable
parameter inmapped_column()
, as well as SQL types without arguments (e.g.,Integer
). -
Replace Optional[type]
withtype | None
. ForMapped
type annotations ofrelationship()
, this can be accomplished by importingannotations
from the__future__
module. This postponed evaluation of annotations also avoids the need for type annotations as string literals. -
Replace legacy use of backref
with explicitrelationship()
constructs usingback_populates
. -
Some minor bug fixes following the proper type annotation of attachment
andbroadcast
modules. -
Index
constructs are moved to__table_args__
for clarity (with two notable exceptions in theworkflow
module). -
Removal of mapped_column()
directives without any parameters. An important exception are columns that later are used in composite foreign key or index constructs, which throws aNameError
if the emptymapped_column()
is removed (possible bug?).
Many of these SQLAlchemy-related style choices should preferably be picked up by mypy. I will be working on implementing some relevant checks in the ella_mypy
plugin.
Notes to review (code/docs/QA)
Related issues
Closes #2242 (closed)
Edited by Vetle Simensen