Skip to content

Commit

Permalink
feat: add some tables
Browse files Browse the repository at this point in the history
  • Loading branch information
osoken committed Sep 28, 2024
1 parent 960f7b5 commit 6876d74
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion common/birdxplorer_common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column, relationship
from sqlalchemy.types import CHAR, DECIMAL, JSON, Integer, String

from .models import BinaryBool, LanguageIdentifier, MediaDetails, NonNegativeInt
from .models import BinaryBool, LanguageIdentifier, LinkId, MediaDetails, NonNegativeInt
from .models import Note as NoteModel
from .models import NoteId, NotesClassification, NotesHarmful, ParticipantId
from .models import Post as PostModel
Expand All @@ -34,6 +34,7 @@ def adapt_pydantic_http_url(url: AnyUrl) -> AsIs:

class Base(DeclarativeBase):
type_annotation_map = {
LinkId: Integer,
TopicId: Integer,
TopicLabel: JSON,
NoteId: String,
Expand Down Expand Up @@ -88,6 +89,14 @@ class XUserRecord(Base):
following_count: Mapped[NonNegativeInt] = mapped_column(nullable=False)


class LinkRecord(Base):
__tablename__ = "links"

link_id: Mapped[LinkId] = mapped_column(primary_key=True)
canonical_url: Mapped[HttpUrl] = mapped_column(nullable=False, index=True)
short_url: Mapped[HttpUrl] = mapped_column(nullable=False, index=True)


class PostRecord(Base):
__tablename__ = "posts"

Expand All @@ -102,6 +111,14 @@ class PostRecord(Base):
impression_count: Mapped[NonNegativeInt] = mapped_column(nullable=False)


class PostLinkAssociation(Base):
__tablename__ = "post_link"

post_id: Mapped[PostId] = mapped_column(ForeignKey("posts.post_id"), primary_key=True)
link_id: Mapped[LinkId] = mapped_column(ForeignKey("links.link_id"), primary_key=True)
link: Mapped["LinkRecord"] = relationship()


class RowNoteRecord(Base):
__tablename__ = "row_notes"

Expand Down

0 comments on commit 6876d74

Please sign in to comment.