CREATE TABLE social.badge (
    id bigserial PRIMARY KEY,
    uid bigint NOT NULL,
    badge_id text NOT NULL,
    level integer,
    awarded_at timestamp with time zone NOT NULL DEFAULT now(),
    awarded_by bigint NOT NULL
);
CREATE INDEX badge_uid_bid_lvl_idx
    ON social.badge (uid, badge_id, level DESC);
