--- user-events


CREATE TABLE user_events (
  id              BIGINT PRIMARY KEY,
  org_id          BIGINT      NOT NULL REFERENCES orgs (id),
  actor           VARCHAR     NOT NULL,
  actor_client_id BIGINT      NULL REFERENCES clients (id),
  actor_user_id   BIGINT      NULL REFERENCES users (id),
  actor_ip        VARCHAR     NOT NULL,
  actor_ua_id     BIGINT      NOT NULL REFERENCES user_agents (id),
  created_at      TIMESTAMPTZ NOT NULL DEFAULT now(),

  type            VARCHAR     NOT NULL,
  user_id         BIGINT      NULL REFERENCES users (id),
  group_id        BIGINT      NULL  REFERENCES user_groups (id),
  member_id       BIGINT      NULL REFERENCES user_groups_members (id)
);

CREATE SEQUENCE user_events_id_seq;
