--- activity-events

create table activity_events (
    id bigint primary key identity (1, 1),
    type nvarchar(255) not null,
    created_at datetimeoffset not null,

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

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

    user_role_id bigint references user_roles(id),
    user_role_title nvarchar(4000),
    user_role_admin bit,
    user_role_permissions nvarchar(4000),

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

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

    group_id bigint references groups(id),
    group_parent_id bigint references groups(id),
    group_title nvarchar(4000),
    group_description nvarchar(4000),
    group_admin bit,
    group_permissions nvarchar(4000),

    group_member_id bigint references group_members(id)
);

create index activity_events_created_ix 
on activity_events(created_at);

create index activity_events_actor_ix
on activity_events(actor_id, created_at);
