Phase 2 Complete: SQL migration with SQLModel and Alembic
This commit is contained in:
+55
-6
@@ -1,8 +1,10 @@
|
||||
"""Pydantic models for Sonarr webhook integration"""
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from pydantic import BaseModel, Field as PydanticField, validator
|
||||
from typing import Optional, Dict, Any, List
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from sqlmodel import SQLModel, Field
|
||||
import uuid
|
||||
|
||||
|
||||
class SonarrEventType(str, Enum):
|
||||
@@ -45,7 +47,7 @@ class SonarrEpisodeFile(BaseModel):
|
||||
|
||||
class SonarrSeries(BaseModel):
|
||||
"""Series information from Sonarr"""
|
||||
tvdbId: int = Field(..., alias="tvdbId")
|
||||
tvdbId: int = PydanticField(..., alias="tvdbId")
|
||||
title: str
|
||||
sortTitle: str
|
||||
status: str
|
||||
@@ -129,8 +131,33 @@ class SonarrWebhookPayload(BaseModel):
|
||||
return v
|
||||
|
||||
|
||||
class SonarrMappingBase(SQLModel):
|
||||
sonarr_series_id: int = Field(index=True, unique=True)
|
||||
sonarr_title: str
|
||||
anime_provider: str
|
||||
anime_url: str
|
||||
anime_title: str
|
||||
lang: str = Field(default="vostfr")
|
||||
quality_preference: Optional[str] = None
|
||||
auto_download: bool = Field(default=True)
|
||||
created_at: datetime = Field(default_factory=datetime.now)
|
||||
updated_at: datetime = Field(default_factory=datetime.now)
|
||||
|
||||
|
||||
class SonarrMappingTable(SonarrMappingBase, table=True):
|
||||
"""Database table for Sonarr mappings"""
|
||||
__tablename__ = "sonarr_mappings"
|
||||
id: str = Field(
|
||||
default_factory=lambda: str(uuid.uuid4()),
|
||||
primary_key=True,
|
||||
index=True,
|
||||
nullable=False
|
||||
)
|
||||
user_id: str = Field(foreign_key="users.id", index=True, default="default")
|
||||
|
||||
|
||||
class SonarrMapping(BaseModel):
|
||||
"""Mapping between Sonarr series and anime providers"""
|
||||
"""Mapping between Sonarr series and anime providers (API model)"""
|
||||
sonarr_series_id: int
|
||||
sonarr_title: str
|
||||
anime_provider: str # 'anime-sama', 'neko-sama', etc.
|
||||
@@ -139,8 +166,8 @@ class SonarrMapping(BaseModel):
|
||||
lang: str = "vostfr"
|
||||
quality_preference: Optional[str] = None # '1080p', '720p', etc.
|
||||
auto_download: bool = True
|
||||
created_at: datetime = Field(default_factory=datetime.now)
|
||||
updated_at: datetime = Field(default_factory=datetime.now)
|
||||
created_at: datetime = PydanticField(default_factory=datetime.now)
|
||||
updated_at: datetime = PydanticField(default_factory=datetime.now)
|
||||
|
||||
class Config:
|
||||
json_encoders = {
|
||||
@@ -148,8 +175,30 @@ class SonarrMapping(BaseModel):
|
||||
}
|
||||
|
||||
|
||||
class SonarrConfigBase(SQLModel):
|
||||
webhook_enabled: bool = Field(default=False)
|
||||
webhook_secret: Optional[str] = None
|
||||
auto_download_enabled: bool = Field(default=True)
|
||||
default_language: str = Field(default="vostfr")
|
||||
default_quality: Optional[str] = None
|
||||
default_provider: str = Field(default="anime-sama")
|
||||
verify_hmac: bool = Field(default=False)
|
||||
log_webhooks: bool = Field(default=True)
|
||||
|
||||
|
||||
class SonarrConfigTable(SonarrConfigBase, table=True):
|
||||
"""Database table for Sonarr configuration (singleton)"""
|
||||
__tablename__ = "sonarr_config"
|
||||
id: str = Field(
|
||||
default_factory=lambda: str(uuid.uuid4()),
|
||||
primary_key=True,
|
||||
index=True,
|
||||
nullable=False
|
||||
)
|
||||
|
||||
|
||||
class SonarrConfig(BaseModel):
|
||||
"""Sonarr webhook configuration"""
|
||||
"""Sonarr webhook configuration (API Model)"""
|
||||
webhook_enabled: bool = False
|
||||
webhook_secret: Optional[str] = None # HMAC SHA256 secret
|
||||
auto_download_enabled: bool = True
|
||||
|
||||
Reference in New Issue
Block a user