Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mention to reference annotation #9297

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update mention to reference annotation
mtomilov committed Jan 30, 2025

Verified

This commit was signed with the committer’s verified signature.
melroy89 Melroy van den Berg
commit 2547a26b4d3e40f36064a677b148ccffa277c3a9
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Update mention to reference annotation.
Revision ID: 550865ed6622
Revises: 39cc1025a3a2
"""

import sqlalchemy as sa
from alembic import op

from h.db import types

revision = "550865ed6622"
down_revision = "39cc1025a3a2"


def upgrade() -> None:
op.drop_column("mention", "annotation_id")
op.add_column(
"mention",
sa.Column(
"annotation_id",
types.URLSafeUUID(),
sa.ForeignKey("annotation.id", ondelete="CASCADE"),
nullable=False,
),
)


def downgrade() -> None:
op.drop_column("mention", "annotation_id")
op.add_column(
"mention",
sa.Column(
"annotation_id",
sa.INTEGER(),
sa.ForeignKey("annotation_slim.id", ondelete="CASCADE"),
nullable=False,
),
)
2 changes: 2 additions & 0 deletions h/models/annotation.py
Original file line number Diff line number Diff line change
@@ -138,6 +138,8 @@ class Annotation(Base):
uselist=True,
)

mentions = sa.orm.relationship("Mention", back_populates="annotation")

@property
def uuid(self):
"""
12 changes: 6 additions & 6 deletions h/models/mention.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sqlalchemy as sa
from sqlalchemy.orm import Mapped, mapped_column

from h.db import Base
from h.db import Base, types
from h.db.mixins import Timestamps
from h.models import helpers

@@ -11,13 +11,13 @@ class Mention(Base, Timestamps): # pragma: nocover

id: Mapped[int] = mapped_column(sa.Integer, autoincrement=True, primary_key=True)

annotation_id: Mapped[int] = mapped_column(
sa.Integer,
sa.ForeignKey("annotation_slim.id", ondelete="CASCADE"),
annotation_id: Mapped[types.URLSafeUUID] = mapped_column(
types.URLSafeUUID,
sa.ForeignKey("annotation.id", ondelete="CASCADE"),
nullable=False,
)
"""FK to annotation_slim.id"""
annotation = sa.orm.relationship("AnnotationSlim")
"""FK to annotation.id"""
annotation = sa.orm.relationship("Annotation", back_populates="mentions")

user_id: Mapped[int] = mapped_column(
sa.Integer,