migrate db.current_patch_level to SQLAlchemy
This commit is contained in:
parent
e27b57050a
commit
37e8d53b78
3 changed files with 47 additions and 29 deletions
|
|
@ -30,6 +30,7 @@ JSONObject = dict[str, JSON]
|
|||
T = TypeVar("T")
|
||||
|
||||
mapper_registry = registry()
|
||||
metadata = mapper_registry.metadata
|
||||
|
||||
|
||||
def annotations(tp: Type) -> tuple | None:
|
||||
|
|
@ -203,12 +204,29 @@ def utcnow():
|
|||
return datetime.utcnow().replace(tzinfo=timezone.utc)
|
||||
|
||||
|
||||
@mapper_registry.mapped
|
||||
@dataclass
|
||||
class DbPatch:
|
||||
__table__ = Table(
|
||||
"db_patches",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("current", String),
|
||||
)
|
||||
|
||||
id: int
|
||||
current: str
|
||||
|
||||
|
||||
db_patches = DbPatch.__table__
|
||||
|
||||
|
||||
@mapper_registry.mapped
|
||||
@dataclass
|
||||
class Progress:
|
||||
__table__ = Table(
|
||||
"progress",
|
||||
mapper_registry.metadata,
|
||||
metadata,
|
||||
Column("id", String, primary_key=True), # ULID
|
||||
Column("type", String, nullable=False),
|
||||
Column("state", String, nullable=False), # JSON {"percent": ..., "error": ...}
|
||||
|
|
@ -258,7 +276,7 @@ class Progress:
|
|||
class Movie:
|
||||
__table__ = Table(
|
||||
"movies",
|
||||
mapper_registry.metadata,
|
||||
metadata,
|
||||
Column("id", String, primary_key=True), # ULID
|
||||
Column("title", String, nullable=False),
|
||||
Column("original_title", String),
|
||||
|
|
@ -336,7 +354,7 @@ Relation = Annotated[T | None, _RelationSentinel]
|
|||
class Rating:
|
||||
__table__ = Table(
|
||||
"ratings",
|
||||
mapper_registry.metadata,
|
||||
metadata,
|
||||
Column("id", String, primary_key=True), # ULID
|
||||
Column("movie_id", ForeignKey("movies.id"), nullable=False), # ULID
|
||||
Column("user_id", ForeignKey("users.id"), nullable=False), # ULID
|
||||
|
|
@ -393,7 +411,7 @@ class UserGroup(TypedDict):
|
|||
class User:
|
||||
__table__ = Table(
|
||||
"users",
|
||||
mapper_registry.metadata,
|
||||
metadata,
|
||||
Column("id", String, primary_key=True), # ULID
|
||||
Column("imdb_id", String, nullable=False, unique=True),
|
||||
Column("name", String, nullable=False),
|
||||
|
|
@ -433,7 +451,7 @@ class GroupUser(TypedDict):
|
|||
class Group:
|
||||
__table__ = Table(
|
||||
"groups",
|
||||
mapper_registry.metadata,
|
||||
metadata,
|
||||
Column("id", String, primary_key=True), # ULID
|
||||
Column("name", String, nullable=False),
|
||||
Column("users", String, nullable=False), # JSON array
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue