CREATE TABLE IF NOT EXISTS runtime_log_cleanup_audit (
    id TEXT PRIMARY KEY,
    tenant_id TEXT NOT NULL,
    actor_prefix TEXT NOT NULL,
    filename TEXT NOT NULL,
    action TEXT NOT NULL,
    size_before BIGINT NOT NULL,
    size_after BIGINT,
    detail_json JSONB,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    CONSTRAINT runtime_log_cleanup_audit_action_chk CHECK (
        action IN ('truncate', 'delete')
    ),
    CONSTRAINT runtime_log_cleanup_audit_filename_chk CHECK (length(trim(filename)) > 0)
);

CREATE INDEX IF NOT EXISTS idx_runtime_log_cleanup_audit_tenant_created
    ON runtime_log_cleanup_audit (tenant_id, created_at DESC);
