Skip to content

Commit

Permalink
fix: Fixed ondelete for logos and documents
Browse files Browse the repository at this point in the history
  • Loading branch information
kojicmarko committed Mar 11, 2024
1 parent 166b83e commit 5bf0f9f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Install the dependencies
install:
@poetry install
# Run Alembic migrations
# Apply Alembic migrations to database
migrations:
@poetry run alembic upgrade head
# Build docker image
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""updated projects and documents tables
Revision ID: f4541e89938b
Revises: 07ffc299dbad
Create Date: 2024-03-11 14:44:40.749399
"""
from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "f4541e89938b"
down_revision: Union[str, None] = "07ffc299dbad"
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.drop_constraint("documents_project_id_fkey", "documents", type_="foreignkey")
op.create_foreign_key(
None, "documents", "projects", ["project_id"], ["id"], ondelete="CASCADE"
)
op.drop_constraint("projects_logo_id_fkey", "projects", type_="foreignkey")
op.create_foreign_key(
None, "projects", "logos", ["logo_id"], ["id"], ondelete="SET NULL"
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "projects", type_="foreignkey")
op.create_foreign_key(
"projects_logo_id_fkey", "projects", "logos", ["logo_id"], ["id"]
)
op.drop_constraint(None, "documents", type_="foreignkey")
op.create_foreign_key(
"documents_project_id_fkey", "documents", "projects", ["project_id"], ["id"]
)
# ### end Alembic commands ###
1 change: 0 additions & 1 deletion src/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ class Project(Base):
logo_id: Mapped[UUID] = mapped_column(
ForeignKey("logos.id", ondelete="SET NULL"), nullable=True
)
logo = relationship("Logo", cascade="all,delete")
documents = relationship("Document", backref="projects")

0 comments on commit 5bf0f9f

Please sign in to comment.