CREATE TABLE account_errors (
    id          BIGSERIAL PRIMARY KEY,
    account_id  BIGINT NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
    run_id      BIGINT,
    kind        TEXT NOT NULL CHECK (kind IN ('folder','message','account')),
    folder      TEXT NOT NULL DEFAULT '',
    message_ref TEXT NOT NULL DEFAULT '',
    error       TEXT NOT NULL,
    created_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX account_errors_account_id_idx ON account_errors (account_id);
