-- Profile-Page Phase C — Demographics, Pro-Trial-Reward, Lyra-Voice, DiGA-Banner-Persistence
-- Backed by `model Profile` extensions in schema.prisma.
--
-- Drift-Hinweis: Diese Migration wird via `pnpm prisma migrate deploy` auf
-- staging-/prod-DB gefahren. Lokal NICHT ausführen. Falls Drift erkannt wird:
--   pnpm prisma migrate resolve --applied 20260507_profile_demographics_and_trial

ALTER TABLE "rebreak"."profiles"
    ADD COLUMN IF NOT EXISTS "birth_year"                 INTEGER,
    ADD COLUMN IF NOT EXISTS "gender"                     TEXT,
    ADD COLUMN IF NOT EXISTS "marital_status"             TEXT,
    ADD COLUMN IF NOT EXISTS "profession"                 TEXT,
    ADD COLUMN IF NOT EXISTS "bundesland"                 TEXT,
    ADD COLUMN IF NOT EXISTS "city"                       TEXT,
    ADD COLUMN IF NOT EXISTS "demographics_consent_at"    TIMESTAMP(3),
    ADD COLUMN IF NOT EXISTS "demographics_withdrawn_at"  TIMESTAMP(3),
    ADD COLUMN IF NOT EXISTS "lyra_voice_id"              TEXT,
    ADD COLUMN IF NOT EXISTS "pro_trial_started_at"       TIMESTAMP(3),
    ADD COLUMN IF NOT EXISTS "pro_trial_expires_at"       TIMESTAMP(3),
    ADD COLUMN IF NOT EXISTS "pro_trial_source"           TEXT,
    ADD COLUMN IF NOT EXISTS "pro_trial_used_at"          TIMESTAMP(3),
    ADD COLUMN IF NOT EXISTS "diga_banner_dismissed_at"   TIMESTAMP(3),
    ADD COLUMN IF NOT EXISTS "last_install_at"            TIMESTAMP(3);

-- Cron-Helper-Index: schneller find-by-expiry für Trial-Revoke-Cron
CREATE INDEX IF NOT EXISTS "profiles_pro_trial_expires_at_idx"
    ON "rebreak"."profiles"("pro_trial_expires_at")
    WHERE "pro_trial_expires_at" IS NOT NULL;
