-- Dokumentation, siehe README.md. Wird zur Laufzeit idempotent von
-- internal/storage/reminders.go initReminderSchema() erzeugt.

CREATE TABLE IF NOT EXISTS reminders (
    id          BIGSERIAL PRIMARY KEY,
    document_id BIGINT NOT NULL REFERENCES documents(id),
    tenant_id   BIGINT NOT NULL,
    user_id     BIGINT NOT NULL,
    due_date    TIMESTAMPTZ NOT NULL,
    note        TEXT,
    status      TEXT NOT NULL DEFAULT 'open', -- open|done|dismissed
    notified_at TIMESTAMPTZ,
    created_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_reminders_tenant_due ON reminders(tenant_id, due_date) WHERE status = 'open';
CREATE INDEX IF NOT EXISTS idx_reminders_document ON reminders(document_id);
