from datetime import datetime from enum import Enum from pydantic import BaseModel from sqlalchemy import Column, DateTime, func, JSON, Index from sqlalchemy.dialects.mysql import LONGTEXT from sqlmodel import Field, SQLModel, Relationship from app.models.confluence_space import ConfluenceSpace class ConfluenceContentType(str, Enum): PAGE = "page" class ConfluencePage(SQLModel, table=True): __tablename__ = "confluence_pages" __table_args__ = (Index("uni_cp_on_site_id_page_id", "site_id", "id", unique=True),) guid: str = Field( primary_key=True, description="format: SITE-{site_id}-PAGE-{page_id}" ) id: str = Field(nullable=False, max_length=32) version: int = Field(nullable=False) link: str = Field(nullable=False, max_length=256, default="") status: str = Field(nullable=False, max_length=16) author_id: str = Field(nullable=False) title: str = Field(nullable=False, max_length=256) body: str = Field(sa_column=Column(LONGTEXT, nullable=False)) labels: list[str] = Field(sa_column=Column(JSON, nullable=False), default=[]) created_at: datetime = Field(sa_column=Column(DateTime, server_default=func.now())) space_guid: str = Field( nullable=False, max_length=32, foreign_key="confluence_spaces.guid" ) space_id: str = Field(nullable=False, max_length=32) space_key: str = Field(nullable=False, max_length=32) space: "ConfluenceSpace" = Relationship( sa_relationship_kwargs={ "lazy": "joined", "primaryjoin": "ConfluencePage.space_guid == ConfluenceSpace.guid", }, ) site_id: int = Field(nullable=False, foreign_key="confluence_sites.id") site: "ConfluenceSite" = Relationship( sa_relationship_kwargs={ "lazy": "joined", "primaryjoin": "ConfluencePage.site_id == ConfluenceSite.id", }, )