Skip to content

Commit

Permalink
Fix short name uniqueness
Browse files Browse the repository at this point in the history
Short names are unique only within the plan not globally.
  • Loading branch information
LKajan committed Dec 2, 2024
1 parent 185caaa commit 53ad534
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""short name uniqueness fix
Revision ID: e9a045c08304
Revises: 09f44e0e7110
Create Date: 2024-12-02 13:54:23.903091
"""
from typing import Sequence, Union

import geoalchemy2
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "e9a045c08304"
down_revision: Union[str, None] = "09f44e0e7110"
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.alter_column(
"plan_regulation_group",
"short_name",
existing_type=sa.VARCHAR(),
nullable=True,
schema="hame",
)
op.drop_index(
"ix_hame_plan_regulation_group_short_name",
table_name="plan_regulation_group",
schema="hame",
)
op.create_index(
"ix_plan_regulation_group_plan_id_short_name",
"plan_regulation_group",
["plan_id", "short_name"],
unique=True,
schema="hame",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
"ix_plan_regulation_group_plan_id_short_name",
table_name="plan_regulation_group",
schema="hame",
)
op.create_index(
"ix_hame_plan_regulation_group_short_name",
"plan_regulation_group",
["short_name"],
unique=True,
schema="hame",
)
op.alter_column(
"plan_regulation_group",
"short_name",
existing_type=sa.VARCHAR(),
nullable=False,
schema="hame",
)
# ### end Alembic commands ###
9 changes: 7 additions & 2 deletions database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
language_str,
numeric_range,
timestamp,
unique_str,
)
from shapely.geometry import MultiLineString, MultiPoint, MultiPolygon
from sqlalchemy import Column, ForeignKey, Index, Table, Uuid
Expand Down Expand Up @@ -195,10 +194,16 @@ class PlanRegulationGroup(VersionedBase):
__tablename__ = "plan_regulation_group"
__table_args__ = (
Index("ix_plan_regulation_group_plan_id_ordering", "plan_id", "ordering"),
Index(
"ix_plan_regulation_group_plan_id_short_name",
"plan_id",
"short_name",
unique=True,
),
VersionedBase.__table_args__,
)

short_name: Mapped[unique_str]
short_name: Mapped[str] = mapped_column(nullable=True)
name: Mapped[language_str]

plan_id: Mapped[uuid.UUID] = mapped_column(
Expand Down

0 comments on commit 53ad534

Please sign in to comment.