--- user-events


CREATE TABLE user_events (
  id              BIGINT IDENTITY (1,1) PRIMARY KEY,
  org_id          BIGINT      NOT NULL REFERENCES orgs (id),
  actor           NVARCHAR(255)     NOT NULL,
  actor_client_id BIGINT      NULL REFERENCES clients (id),
  actor_user_id   BIGINT      NULL REFERENCES users (id),
  actor_ip        VARCHAR(45)     NOT NULL,
  actor_ua_id     BIGINT      NOT NULL REFERENCES user_agents (id),
  created_at      DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET(),

  type            VARCHAR(64)     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)
);
