CREATE TABLE IF NOT EXISTS mail_sync_alert_state (
    tenant_slug          TEXT NOT NULL,
    mailbox_name         TEXT NOT NULL,
    consecutive_failures INT NOT NULL DEFAULT 0,
    alerted              BOOLEAN NOT NULL DEFAULT false,
    last_success_at      TIMESTAMPTZ,
    last_failure_reason  TEXT,
    last_failure_at      TIMESTAMPTZ,
    updated_at           TIMESTAMPTZ NOT NULL DEFAULT now(),
    PRIMARY KEY (tenant_slug, mailbox_name)
)
