Skip to content

Commit

Permalink
unique tag name per user
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Nov 19, 2024
1 parent 3e2fee6 commit 597f64e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Initial migration
Revision ID: 74a3ec08d4e0
Revision ID: bc29f69daca4
Revises:
Create Date: 2024-11-19 09:49:31.706007
Create Date: 2024-11-19 11:01:46.706986
"""
from typing import Sequence, Union
Expand All @@ -12,7 +12,7 @@


# revision identifiers, used by Alembic.
revision: str = '74a3ec08d4e0'
revision: str = 'bc29f69daca4'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Expand Down Expand Up @@ -55,7 +55,7 @@ def upgrade() -> None:
sa.Column('user_id', sa.Uuid(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='tag_user_id_fk', use_alter=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
sa.UniqueConstraint('name', 'user_id', name='unique tag name per user')
)
op.create_table('folders',
sa.Column('node_id', sa.Uuid(), nullable=False),
Expand Down
10 changes: 7 additions & 3 deletions papermerge/core/features/tags/db/orm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from sqlalchemy import Column, ForeignKey, Table
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy import ForeignKey, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column

from papermerge.core.db.base import Base

Expand All @@ -18,7 +18,7 @@ class Tag(Base):
__tablename__ = "tags"

id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
name: Mapped[str] = mapped_column(unique=True)
name: Mapped[str]
fg_color: Mapped[str] = mapped_column(nullable=True, default="#FFFFF")
bg_color: Mapped[str] = mapped_column(nullable=True, default="#c41fff")
pinned: Mapped[bool] = mapped_column(default=False)
Expand All @@ -27,5 +27,9 @@ class Tag(Base):
ForeignKey("users.id", use_alter=True, name="tag_user_id_fk")
)

__table_args__ = (
UniqueConstraint("name", "user_id", name="unique tag name per user"),
)

def __repr__(self):
return f"Tag(name={self.name})"

0 comments on commit 597f64e

Please sign in to comment.