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

fix: add event to notes #25

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
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
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)
Loading