Skip to content

Commit

Permalink
Merge pull request #25 from cs3216-a3-group-4/seeleng/add-event-to-notes
Browse files Browse the repository at this point in the history
fix: add event to notes
  • Loading branch information
seelengxd authored Sep 22, 2024
2 parents 9dd4db3 + 87ddb54 commit be5d353
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
44 changes: 44 additions & 0 deletions backend/alembic/versions/d79f0e188c13_add_events_to_note.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Add events to note
Revision ID: d79f0e188c13
Revises: 37cf2356fe08
Create Date: 2024-09-23 02:56:34.941075
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "d79f0e188c13"
down_revision: Union[str, None] = "37cf2356fe08"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"event_note",
sa.Column("event_id", sa.Integer(), nullable=False),
sa.Column("note_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["event_id"],
["event.id"],
),
sa.ForeignKeyConstraint(
["note_id"],
["note.id"],
),
sa.PrimaryKeyConstraint("event_id", "note_id"),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("event_note")
# ### end Alembic commands ###
11 changes: 10 additions & 1 deletion backend/src/notes/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlalchemy import Enum, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.orm import Mapped, mapped_column, relationship
from src.common.base import Base


Expand All @@ -24,3 +24,12 @@ class Note(Base):
user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))

__mapper_args__ = {"polymorphic_on": "parent_type", "polymorphic_identity": "note"}

events = relationship("Event", secondary="event_note")


class EventNote(Base):
__tablename__ = "event_note"

event_id: Mapped[int] = mapped_column(ForeignKey("event.id"), primary_key=True)
note_id: Mapped[int] = mapped_column(ForeignKey("note.id"), primary_key=True)

0 comments on commit be5d353

Please sign in to comment.