--- activity-events

create table activity_events (
    id number(19) primary key,
    type varchar2(255 char) not null,
    created_at timestamp with time zone not null,

    actor_id number(19) references users(id),
    actor_session_id number(19) references user_sessions(id),
    actor_ip varchar2(255 char),
    actor_ua varchar2(4000 char),

    user_id number(19) references users(id),
    user_name varchar2(4000 char),
    user_email varchar2(4000 char),
    user_position varchar2(4000 char),

    user_role_id number(19) references user_roles(id),
    user_role_title varchar2(4000 char),
    user_role_admin number(1),
    user_role_permissions varchar2(4000 char),

    user_session_id number(19) references user_sessions(id),
    user_login_error varchar2(4000),

    project_id number(19) references projects(id),
    project_name varchar2(4000 char),
    project_slug varchar2(4000 char),
    project_description varchar2(4000 char),
    project_state varchar2(4000 char),

    group_id number(19) references groups(id),
    group_parent_id number(19) references groups(id),
    group_title varchar2(4000 char),
    group_description varchar2(4000 char),
    group_admin number(1),
    group_permissions varchar2(4000 char),

    group_member_id number(19) 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);
