64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
import uuid
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Text
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.dialects.postgresql.json import JSONB
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from ..database import Base
|
|
|
|
|
|
class ArticleEntity(Base):
|
|
__tablename__ = "article"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
article_type: Mapped[str] = mapped_column(Text, nullable=False)
|
|
language: Mapped[str] = mapped_column(Text, nullable=False)
|
|
target_complexity: Mapped[str] = mapped_column(Text, nullable=False)
|
|
title: Mapped[str] = mapped_column(Text, nullable=False)
|
|
text: Mapped[str] = mapped_column(Text, nullable=False)
|
|
text_linguistic_data: Mapped[dict] = mapped_column(JSONB, nullable=True)
|
|
audio_key: Mapped[str] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
nullable=False,
|
|
default=lambda: datetime.now(timezone.utc),
|
|
)
|
|
published_at: Mapped[datetime | None] = mapped_column(
|
|
DateTime(timezone=True), nullable=True
|
|
)
|
|
deleted_at: Mapped[datetime | None] = mapped_column(
|
|
DateTime(timezone=True), nullable=True
|
|
)
|
|
|
|
|
|
class ArticleOwnershipEntity(Base):
|
|
__tablename__ = "article_ownership"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
article_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("article.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
ownership_role: Mapped[str] = mapped_column(Text, nullable=False)
|
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
nullable=False,
|
|
default=lambda: datetime.now(timezone.utc),
|
|
)
|
|
deleted_at: Mapped[datetime | None] = mapped_column(
|
|
DateTime(timezone=True), nullable=True
|
|
)
|