mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
Switch igdb/sgdb IDs to int + update fastapi/pydantic
This commit is contained in:
@@ -47,6 +47,7 @@ def run_migrations_offline() -> None:
|
||||
render_as_batch=True,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
compare_type=True,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
@@ -65,7 +66,10 @@ def run_migrations_online() -> None:
|
||||
|
||||
with engine.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection, target_metadata=target_metadata, render_as_batch=True
|
||||
connection=connection,
|
||||
target_metadata=target_metadata,
|
||||
render_as_batch=True,
|
||||
compare_type=True,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
|
||||
@@ -10,7 +10,7 @@ import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "88c425843d1e"
|
||||
revision = "0009_models_refactor"
|
||||
down_revision = "1.9.2"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
88
backend/alembic/versions/0010_igdb_id_integerr.py
Normal file
88
backend/alembic/versions/0010_igdb_id_integerr.py
Normal file
@@ -0,0 +1,88 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 00e2b1d2d5ec
|
||||
Revises: 0009_models_refactor
|
||||
Create Date: 2023-09-14 09:57:13.487331
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "00e2b1d2d5ec"
|
||||
down_revision = "0009_models_refactor"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("platforms", schema=None) as batch_op:
|
||||
batch_op.execute('UPDATE platforms SET igdb_id = NULL WHERE igdb_id = ""')
|
||||
batch_op.execute('UPDATE platforms SET sgdb_id = NULL WHERE sgdb_id = ""')
|
||||
|
||||
batch_op.alter_column(
|
||||
"igdb_id",
|
||||
existing_type=mysql.VARCHAR(length=10),
|
||||
type_=sa.Integer(),
|
||||
existing_nullable=True,
|
||||
)
|
||||
batch_op.alter_column(
|
||||
"sgdb_id",
|
||||
existing_type=mysql.VARCHAR(length=10),
|
||||
type_=sa.Integer(),
|
||||
existing_nullable=True,
|
||||
)
|
||||
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.execute('UPDATE roms SET igdb_id = NULL WHERE igdb_id = ""')
|
||||
batch_op.execute('UPDATE roms SET sgdb_id = NULL WHERE sgdb_id = ""')
|
||||
|
||||
batch_op.alter_column(
|
||||
"igdb_id",
|
||||
existing_type=mysql.VARCHAR(length=10),
|
||||
type_=sa.Integer(),
|
||||
existing_nullable=True,
|
||||
)
|
||||
batch_op.alter_column(
|
||||
"sgdb_id",
|
||||
existing_type=mysql.VARCHAR(length=10),
|
||||
type_=sa.Integer(),
|
||||
existing_nullable=True,
|
||||
)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"sgdb_id",
|
||||
existing_type=sa.Integer(),
|
||||
type_=mysql.VARCHAR(length=10),
|
||||
existing_nullable=True,
|
||||
)
|
||||
batch_op.alter_column(
|
||||
"igdb_id",
|
||||
existing_type=sa.Integer(),
|
||||
type_=mysql.VARCHAR(length=10),
|
||||
existing_nullable=True,
|
||||
)
|
||||
|
||||
with op.batch_alter_table("platforms", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"sgdb_id",
|
||||
existing_type=sa.Integer(),
|
||||
type_=mysql.VARCHAR(length=10),
|
||||
existing_nullable=True,
|
||||
)
|
||||
batch_op.alter_column(
|
||||
"igdb_id",
|
||||
existing_type=sa.Integer(),
|
||||
type_=mysql.VARCHAR(length=10),
|
||||
existing_nullable=True,
|
||||
)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -2,7 +2,7 @@ import secrets
|
||||
from typing import Optional, Annotated
|
||||
from fastapi import APIRouter, HTTPException, status, Request, Depends, File, UploadFile
|
||||
from fastapi.security.http import HTTPBasic
|
||||
from pydantic import BaseModel, BaseConfig
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from handler import dbh
|
||||
from models.user import User, Role
|
||||
@@ -17,6 +17,8 @@ router = APIRouter()
|
||||
|
||||
|
||||
class UserSchema(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
username: str
|
||||
enabled: bool
|
||||
@@ -24,9 +26,6 @@ class UserSchema(BaseModel):
|
||||
oauth_scopes: list[str]
|
||||
avatar_path: str
|
||||
|
||||
class Config(BaseConfig):
|
||||
orm_mode = True
|
||||
|
||||
|
||||
@router.post("/login")
|
||||
def login(request: Request, credentials=Depends(HTTPBasic())):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from fastapi import APIRouter, Request
|
||||
from pydantic import BaseModel, BaseConfig
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from typing import Optional
|
||||
|
||||
from handler import dbh
|
||||
@@ -9,17 +9,16 @@ router = APIRouter()
|
||||
|
||||
|
||||
class PlatformSchema(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
slug: str
|
||||
fs_slug: str
|
||||
igdb_id: Optional[int] = None
|
||||
sgdb_id: Optional[int] = None
|
||||
name: Optional[str]
|
||||
igdb_id: Optional[str]
|
||||
sgdb_id: Optional[str]
|
||||
logo_path: str
|
||||
rom_count: int
|
||||
|
||||
class Config(BaseConfig):
|
||||
orm_mode = True
|
||||
|
||||
|
||||
@protected_route(router.get, "/platforms", ["platforms.read"])
|
||||
def platforms(request: Request) -> list[PlatformSchema]:
|
||||
|
||||
@@ -12,7 +12,7 @@ from fastapi import (
|
||||
from fastapi_pagination.ext.sqlalchemy import paginate
|
||||
from fastapi_pagination.cursor import CursorPage, CursorParams
|
||||
from fastapi.responses import FileResponse
|
||||
from pydantic import BaseModel, BaseConfig
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from stat import S_IFREG
|
||||
from stream_zip import ZIP_64, stream_zip # type: ignore[import]
|
||||
@@ -40,10 +40,11 @@ router = APIRouter()
|
||||
|
||||
|
||||
class RomSchema(BaseModel):
|
||||
id: int
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
igdb_id: Optional[str]
|
||||
sgdb_id: Optional[str]
|
||||
id: int
|
||||
igdb_id: Optional[int]
|
||||
sgdb_id: Optional[int]
|
||||
|
||||
platform_slug: str
|
||||
platform_name: str
|
||||
@@ -74,8 +75,6 @@ class RomSchema(BaseModel):
|
||||
full_path: str
|
||||
download_path: str
|
||||
|
||||
class Config(BaseConfig):
|
||||
orm_mode = True
|
||||
|
||||
|
||||
@protected_route(router.get, "/roms/{id}", ["roms.read"])
|
||||
|
||||
@@ -156,7 +156,7 @@ class IGDBHandler:
|
||||
or self._search_rom(uc(search_term), platform_idgb_id)
|
||||
)
|
||||
|
||||
igdb_id = res.get("id", 0)
|
||||
igdb_id = res.get("id", None)
|
||||
slug = res.get("slug", "")
|
||||
name = res.get("name", search_term)
|
||||
summary = res.get("summary", "")
|
||||
|
||||
@@ -10,8 +10,8 @@ class Platform(BaseModel):
|
||||
slug: str = Column(String(length=50), primary_key=True)
|
||||
fs_slug: str = Column(String(length=50), nullable=False)
|
||||
name: str = Column(String(length=400))
|
||||
igdb_id: str = Column(String(length=10))
|
||||
sgdb_id: str = Column(String(length=10))
|
||||
igdb_id: str = Column(Integer())
|
||||
sgdb_id: str = Column(Integer())
|
||||
logo_path: str = Column(String(length=1000), default=DEFAULT_PATH_COVER_S)
|
||||
|
||||
### DEPRECATED ###
|
||||
|
||||
@@ -11,8 +11,8 @@ class Rom(BaseModel):
|
||||
__tablename__ = "roms"
|
||||
id = Column(Integer(), primary_key=True, autoincrement=True)
|
||||
|
||||
igdb_id: str = Column(String(length=10))
|
||||
sgdb_id: str = Column(String(length=10))
|
||||
igdb_id: str = Column(Integer())
|
||||
sgdb_id: str = Column(Integer())
|
||||
|
||||
# Foreign key to platform
|
||||
platform_slug = Column(
|
||||
|
||||
793
poetry.lock
generated
793
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@ readme = "README.md"
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
requests = "2.31.0"
|
||||
fastapi = "0.95.1"
|
||||
fastapi = "0.103.1"
|
||||
uvicorn = "0.22.0"
|
||||
websockets = "11.0.3"
|
||||
python-socketio = "5.8.0"
|
||||
|
||||
Reference in New Issue
Block a user