create table events
(
    uuid        varchar(36) default uuid()           not null comment 'The unique universal identifier for the event'
        primary key,
    code        varchar(36) default 'GENERIC'        not null comment 'A short-code event name that represents the event that has occured, the message field will contain more details in regards to the event code used.',
    type        varchar(36) default 'INFO'           not null comment 'The event type, can be INFO, WARN, or ERR',
    client_uuid varchar(36)                          null comment 'The client that created/caused the event',
    peer        varchar(256)                         null comment 'Optional. The peer that is associated with this event',
    message     text                                 null comment 'The event details',
    exception   blob                                 null comment 'The optional exeception details in a serialized format (MSGPACK)',
    timestamp   bigint      default unix_timestamp() not null comment 'The Unix Timestamp for the record',
    constraint events_uuid_uindex
        unique (uuid),
    constraint events_clients_uuid_fk
        foreign key (client_uuid) references clients (uuid),
    constraint events_peers_federated_address_fk
        foreign key (peer) references peers (federated_address)
)
    comment 'A table for housing event logs created by FederationLib in regards to Database changes.';

create index events_client_uuid_index
    on events (client_uuid);

create index events_code_index
    on events (code);

create index events_peer_index
    on events (peer);

create index events_timestamp_index
    on events (timestamp);

create index events_type_index
    on events (type);