fix(inspections): pruefung.geraet_instanz_id FK mit ON DELETE CASCADE (CI-Fix, DELETE /geraete/{id} war blockiert)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
This commit is contained in:
1 parent
25437ec070
commit
ad4483e18c
2 files changed
+37
-1
No files matched your search
@@ -0,0 +1,33 @@
|
||||
"""CI-Fix: pruefung.geraet_instanz_id braucht ON DELETE CASCADE - Löschen
|
||||
einer GeraetInstanz (bestehender Endpunkt DELETE /geraete/{id}) verletzte
|
||||
sonst die neue Foreign Key aus Migration 0045.
|
||||
|
||||
Revision ID: 0046_pruefung_fk_cascade
|
||||
Revises: 0045_pruefung
|
||||
Create Date: 2026-09-10
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0046_pruefung_fk_cascade"
|
||||
down_revision: Union[str, None] = "0045_pruefung"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute("ALTER TABLE pruefung DROP CONSTRAINT pruefung_geraet_instanz_id_fkey")
|
||||
op.execute(
|
||||
"ALTER TABLE pruefung ADD CONSTRAINT pruefung_geraet_instanz_id_fkey "
|
||||
"FOREIGN KEY (geraet_instanz_id) REFERENCES geraet_instanz(id) ON DELETE CASCADE"
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.execute("ALTER TABLE pruefung DROP CONSTRAINT pruefung_geraet_instanz_id_fkey")
|
||||
op.execute(
|
||||
"ALTER TABLE pruefung ADD CONSTRAINT pruefung_geraet_instanz_id_fkey "
|
||||
"FOREIGN KEY (geraet_instanz_id) REFERENCES geraet_instanz(id)"
|
||||
)
|
||||
@@ -60,8 +60,11 @@ class Pruefung(Base):
|
||||
__tablename__ = "pruefung"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
# ON DELETE CASCADE: Löschen einer GeraetInstanz (DELETE /geraete/{id})
|
||||
# räumt ihre Prüfhistorie mit auf, statt den bestehenden Lösch-Endpunkt zu
|
||||
# blockieren (CI-Fund 2026-09-10, siehe Migration 0046).
|
||||
geraet_instanz_id: Mapped[uuid.UUID | None] = mapped_column(
|
||||
UUID(as_uuid=True), ForeignKey("geraet_instanz.id")
|
||||
UUID(as_uuid=True), ForeignKey("geraet_instanz.id", ondelete="CASCADE")
|
||||
)
|
||||
objekt_id: Mapped[int | None] = mapped_column(ForeignKey("objekt.id"))
|
||||
pruefart_id: Mapped[int] = mapped_column(ForeignKey("pruefart.id"), nullable=False)
|
||||
|
||||
Reference in new issue
Block a user