Set platform metadata slugs on models in DB

This commit is contained in:
Georges-Antoine Assi
2025-09-22 21:48:45 -04:00
parent c876ff5b3c
commit 6eed0b6c7f
4 changed files with 47 additions and 18 deletions

View File

@@ -0,0 +1,38 @@
"""empty message
Revision ID: 0054_add_platform_metadata_slugs
Revises: 0053_add_hltb_metadata
Create Date: 2025-09-22 21:42:33.654137
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "0054_add_platform_metadata_slugs"
down_revision = "0053_add_hltb_metadata"
branch_labels = None
depends_on = None
def upgrade() -> None:
with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.add_column(sa.Column("flashpoint_id", sa.Integer(), nullable=True))
batch_op.add_column(
sa.Column("igdb_slug", sa.String(length=100), nullable=True)
)
batch_op.add_column(
sa.Column("moby_slug", sa.String(length=100), nullable=True)
)
batch_op.add_column(
sa.Column("hltb_slug", sa.String(length=100), nullable=True)
)
def downgrade() -> None:
with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.drop_column("hltb_slug")
batch_op.drop_column("moby_slug")
batch_op.drop_column("igdb_slug")
batch_op.drop_column("flashpoint_id")

View File

@@ -16,6 +16,7 @@ class PlatformSchema(BaseModel):
name: str
igdb_slug: str | None
moby_slug: str | None
hltb_slug: str | None
custom_name: str | None = None
igdb_id: int | None = None
sgdb_id: int | None = None
@@ -25,6 +26,7 @@ class PlatformSchema(BaseModel):
ra_id: int | None = None
hasheous_id: int | None = None
tgdb_id: int | None = None
flashpoint_id: int | None = None
category: str | None = None
generation: int | None = None
family_name: str | None = None

View File

@@ -176,8 +176,10 @@ async def scan_platform(
platform_attrs["name"] = platform_attrs["slug"].replace("-", " ").title()
platform_attrs.update(
{
**hasheous_platform,
**hltb_platform,
**flashpoint_platform,
**tgdb_platform,
**hasheous_platform,
**launchbox_platform,
**ra_platform,
**moby_platform,

View File

@@ -1,6 +1,5 @@
from __future__ import annotations
from functools import cached_property
from typing import TYPE_CHECKING
from sqlalchemy import String, func, select
@@ -28,6 +27,10 @@ class Platform(BaseModel):
launchbox_id: Mapped[int | None]
hasheous_id: Mapped[int | None]
tgdb_id: Mapped[int | None]
flashpoint_id: Mapped[int | None]
igdb_slug: Mapped[str | None]
moby_slug: Mapped[str | None]
hltb_slug: Mapped[str | None]
slug: Mapped[str] = mapped_column(String(length=100))
fs_slug: Mapped[str] = mapped_column(String(length=100))
name: Mapped[str] = mapped_column(String(length=400))
@@ -83,21 +86,5 @@ class Platform(BaseModel):
def is_identified(self) -> bool:
return not self.is_unidentified
@cached_property
def igdb_slug(self) -> str | None:
from handler.metadata import meta_igdb_handler
igdb_platform = meta_igdb_handler.get_platform(self.slug)
return igdb_platform.get("igdb_slug", None)
@cached_property
def moby_slug(self) -> str | None:
from handler.metadata import meta_moby_handler
moby_platform = meta_moby_handler.get_platform(self.slug)
return moby_platform.get("moby_slug", None)
def __repr__(self) -> str:
return self.name