Refactored DB schema. Channels table to have uuid as primary key. Modified endpoints accordingly
Some checks failed
AWS Deploy on Push / build (push) Failing after 1m9s

This commit is contained in:
2025-05-22 11:34:04 -05:00
parent 5ee6cb4be4
commit 9e8df169fc
5 changed files with 72 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
from .db import Base, ChannelDB
from .schemas import ChannelCreate, ChannelResponse
from .schemas import ChannelCreate, ChannelUpdate, ChannelResponse
__all__ = ["Base", "ChannelDB", "ChannelCreate", "ChannelResponse"]
__all__ = ["Base", "ChannelDB", "ChannelCreate", "ChannelUpdate", "ChannelResponse"]

View File

@@ -1,5 +1,7 @@
from datetime import datetime, timezone
from sqlalchemy import Column, String, JSON, DateTime
import uuid
from sqlalchemy import Column, String, JSON, DateTime, UniqueConstraint
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
@@ -8,10 +10,15 @@ class ChannelDB(Base):
"""SQLAlchemy model for IPTV channels"""
__tablename__ = "channels"
tvg_id = Column(String, primary_key=True)
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
tvg_id = Column(String, nullable=False)
name = Column(String, nullable=False)
group_title = Column(String)
group_title = Column(String, nullable=False)
tvg_name = Column(String)
__table_args__ = (
UniqueConstraint('group_title', 'name', name='uix_group_title_name'),
)
tvg_logo = Column(String)
urls = Column(JSON) # Stores list of URLs as JSON
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))

View File

@@ -1,5 +1,6 @@
from datetime import datetime
from typing import List
from uuid import UUID
from pydantic import BaseModel
class ChannelCreate(BaseModel):
@@ -11,7 +12,15 @@ class ChannelCreate(BaseModel):
tvg_logo: str
tvg_name: str
class ChannelUpdate(ChannelCreate):
"""Pydantic model for updating channels"""
pass
class ChannelResponse(ChannelCreate):
"""Pydantic model for channel responses"""
id: UUID
created_at: datetime
updated_at: datetime
updated_at: datetime
class Config:
from_attributes = True