CREATE TABLE if not exists gis.services_users_rel
(
  services_rel_id text NOT NULL DEFAULT admin.next_id(),
  service_id text NOT NULL,
  user_id text NOT NULL,
  actions text[],
  created_at timestamp without time zone DEFAULT date_trunc('minutes'::text, (now())::timestamp without time zone),
  updated_at timestamp without time zone,
  updated_by text,
  created_by text,
  CONSTRAINT services_rel_pkey PRIMARY KEY (services_rel_id),
  CONSTRAINT user_id_fkey FOREIGN KEY (user_id)
      REFERENCES admin.users (uid) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT services_user_id_unique UNIQUE (service_id, user_id)
);

CREATE INDEX if not exists services_users_rel_service_id_btree_idx
  ON gis.services_users_rel
  USING btree
  (service_id);

ALTER TABLE admin.users ADD COLUMN IF NOT EXISTS all_layers boolean NOT NULL DEFAULT false;