"""IDENT-005: Hersteller/Modell-Stammdaten, geraet_instanz.modell_id. Revision ID: 0030_hersteller_modell Revises: 0029_dokument_original Create Date: 2026-09-08 """ from typing import Sequence, Union from alembic import op revision: str = "0030_hersteller_modell" down_revision: Union[str, None] = "0029_dokument_original" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: op.execute( """ CREATE TABLE hersteller ( id SERIAL PRIMARY KEY, name TEXT NOT NULL UNIQUE ) """ ) op.execute( """ CREATE TABLE modell ( id SERIAL PRIMARY KEY, hersteller_id INTEGER NOT NULL REFERENCES hersteller(id), name TEXT NOT NULL, UNIQUE (hersteller_id, name) ) """ ) op.execute("CREATE INDEX ix_modell_hersteller_id ON modell (hersteller_id)") op.execute("ALTER TABLE geraet_instanz ADD COLUMN modell_id INTEGER REFERENCES modell(id)") op.execute("CREATE INDEX ix_geraet_instanz_modell_id ON geraet_instanz (modell_id)") def downgrade() -> None: op.execute("DROP INDEX IF EXISTS ix_geraet_instanz_modell_id") op.execute("ALTER TABLE geraet_instanz DROP COLUMN modell_id") op.execute("DROP INDEX IF EXISTS ix_modell_hersteller_id") op.execute("DROP TABLE modell") op.execute("DROP TABLE hersteller")