Adventure Labs Logo
Scout Docs

User_earthranger_ids

Per-herd EarthRanger subject ids for users whose herds use different EarthRanger instances

Column NameData TypeConstraints
user_iduuidNOT NULL, FK -> users (cascade), PK part
herd_idbigintNOT NULL, FK -> herds (cascade), PK part
earthranger_idtextNOT NULL, non-blank
inserted_attimestamp with time zoneDEFAULT timezone('utc', now()) NOT NULL
updated_attimestamp with time zoneDEFAULT timezone('utc', now()) NOT NULL, maintained by trigger

One row per (user_id, herd_id). users.earthranger_id remains as the legacy single id and is the fallback when no row exists for a herd; the migration seeded one row per active membership from it. Resolve with public.user_earthranger_id(user_id, herd_id). It returns the per-herd row when one exists, otherwise the legacy column, and null when the caller is not the user, a platform superadmin, or a holder of herds.read in that herd. Merging two accounts moves the source's rows to the target for herds the target has no row in.

Security Policies (RLS)

RLS enabled. Herd scope: Herd from user_earthranger_ids.herd_id.

Operationhas_herd_ability ability keyOther paths
SELECTherds.readOwn rows (user_id = auth.uid())
INSERT / UPDATE / DELETEusers_roles_per_herd.writeOwn rows, if the user is an active member of that herd

Platform superadmin: FOR ALL bypass.

On this page