Skip to content

Commit

Permalink
Merge pull request #431 from uhh-lt/add-tag-unique-constraint
Browse files Browse the repository at this point in the history
added unique constraint to document tags (name is unique per project now)
  • Loading branch information
bigabig authored Oct 7, 2024
2 parents 4ce9308 + 809c148 commit 9b52616
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
39 changes: 39 additions & 0 deletions backend/src/alembic/versions/5bcc9d14725a_vscode_launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""add tag unique constraint
Revision ID: 5bcc9d14725a
Revises: 00e56404d2b2
Create Date: 2024-10-07 13:03:01.694780
"""

from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "5bcc9d14725a"
down_revision: Union[str, None] = "00e56404d2b2"
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("UC_name_unique_per_project", "code", type_="unique")
op.create_unique_constraint(
"UC_code_name_unique_per_project", "code", ["project_id", "name"]
)
op.create_unique_constraint(
"UC_tag_name_unique_per_project", "documenttag", ["project_id", "name"]
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("UC_tag_name_unique_per_project", "documenttag", type_="unique")
op.drop_constraint("UC_code_name_unique_per_project", "code", type_="unique")
op.create_unique_constraint(
"UC_name_unique_per_project", "code", ["project_id", "name"]
)
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion backend/src/app/core/data/orm/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ class CodeORM(ORMBase):
UniqueConstraint(
"project_id",
"name",
name="UC_name_unique_per_project",
name="UC_code_name_unique_per_project",
),
)
10 changes: 9 additions & 1 deletion backend/src/app/core/data/orm/document_tag.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import TYPE_CHECKING, List, Optional

from sqlalchemy import DateTime, ForeignKey, Integer, String, func
from sqlalchemy import DateTime, ForeignKey, Integer, String, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.core.data.orm.orm_base import ORMBase
Expand Down Expand Up @@ -57,6 +57,14 @@ class DocumentTagORM(ORMBase):
)
parent: Mapped["DocumentTagORM"] = relationship("DocumentTagORM", remote_side=[id])

__table_args__ = (
UniqueConstraint(
"project_id",
"name",
name="UC_tag_name_unique_per_project",
),
)


class SourceDocumentDocumentTagLinkTable(ORMBase):
source_document_id: Mapped[int] = mapped_column(
Expand Down

0 comments on commit 9b52616

Please sign in to comment.