-- Migration 034: Create untersuchungen table (FDISK sync)
CREATE TABLE IF NOT EXISTS untersuchungen (
  id              UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
  user_id         UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  datum           DATE,
  anmerkungen     TEXT,
  art             VARCHAR(128) NOT NULL,
  ergebnis        VARCHAR(128),
  fdisk_sync_key  VARCHAR(255),
  created_at      TIMESTAMPTZ DEFAULT NOW(),
  updated_at      TIMESTAMPTZ DEFAULT NOW(),
  UNIQUE(user_id, fdisk_sync_key)
);

CREATE INDEX IF NOT EXISTS idx_untersuchungen_user_id ON untersuchungen(user_id);
CREATE INDEX IF NOT EXISTS idx_untersuchungen_art ON untersuchungen(user_id, art);
