--- activity-events

create table activity_events (
    id bigint primary key,
    type varchar(255) not null,
    created_at timestamp with time zone not null,

    actor_id bigint references users(id),
    actor_session_id bigint references user_sessions(id),
    actor_ip varchar(255),
    actor_ua varchar(4000),

    user_id bigint references users(id),
    user_name varchar(4000),
    user_email varchar(4000),
    user_position varchar(4000),

    user_role_id bigint references user_roles(id),
    user_role_title varchar(4000),
    user_role_admin boolean,
    user_role_permissions varchar(4000),

    user_session_id bigint references user_sessions(id),
    user_login_error varchar(4000),

    project_id bigint references projects(id),
    project_name varchar(4000),
    project_slug varchar(4000),
    project_description varchar(4000),
    project_state varchar(4000),

    group_id bigint references groups(id),
    group_parent_id bigint references groups(id),
    group_title varchar(4000),
    group_description varchar(4000),
    group_admin boolean,
    group_permissions varchar(4000),

    group_member_id bigint references group_members(id)
);

create sequence activity_events_id_seq;

create index activity_events_created_ix 
on activity_events(created_at);

create index activity_events_actor_ix
on activity_events(actor_id, created_at);
