change database schema for linking table from unique constraint to partial index

This commit is contained in:
2026-07-22 10:17:00 +02:00
parent 65e3e10e13
commit 9a73f27518
2 changed files with 217 additions and 164 deletions
@@ -0,0 +1,47 @@
"""change unique constraint to partial index for company person linking table
Revision ID: 665259cdfdc0
Revises: 03d4f000f445
Create Date: 2026-07-22 10:14:43.889298
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "665259cdfdc0"
down_revision: Union[str, Sequence[str], None] = "03d4f000f445"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("zuordnung_personen_unternehmen", schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f("uq_un_id_pers_id"), type_="unique")
batch_op.create_index(
"uq_aktive_zuordnung",
["un_id", "pers_id"],
unique=True,
sqlite_where=sa.text("gueltig_bis IS NULL"),
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("zuordnung_personen_unternehmen", schema=None) as batch_op:
batch_op.drop_index(
"uq_aktive_zuordnung", sqlite_where=sa.text("gueltig_bis IS NULL")
)
batch_op.create_unique_constraint(
batch_op.f("uq_un_id_pers_id"), ["un_id", "pers_id"]
)
# ### end Alembic commands ###