Add SQL schema, CLI commands, and initialization logic

This commit is contained in:
netkas 2024-09-25 00:40:46 -04:00
parent bc6e814c42
commit ff1363c63f
12 changed files with 327 additions and 1 deletions

View file

@ -0,0 +1,18 @@
create table password_authentication
(
peer_uuid varchar(36) not null comment 'The Primary unique Index for the peer UUID'
primary key,
value varchar(128) not null comment 'The hash value of the pasword',
updated timestamp default current_timestamp() not null comment 'The Timestamp for when this record was last updated',
constraint password_authentication_peer_uuid_uindex
unique (peer_uuid) comment 'The Primary unique Index for the peer UUID',
constraint password_authentication_registered_peers_uuid_fk
foreign key (peer_uuid) references registered_peers (uuid)
on update cascade on delete cascade
)
comment 'Table for housing password authentications associated with peers';
create index password_authentication_updated_index
on password_authentication (updated)
comment 'The Indefor the updated timestamp';

View file

@ -0,0 +1,20 @@
create table registered_peers
(
uuid varchar(36) default uuid() not null comment 'The Primary index for the peer uuid'
primary key,
username varchar(255) not null comment 'The Unique username associated with the peer',
flags text null comment 'Comma seprted flags associated with the peer',
registered timestamp default current_timestamp() not null comment 'The Timestamp for when the peer was registered on the network',
constraint registered_peers_pk_2
unique (username) comment 'The unique username for the peer',
constraint registered_peers_username_uindex
unique (username) comment 'The unique username for the peer',
constraint registered_peers_uuid_uindex
unique (uuid) comment 'The Primary index for the peer uuid'
)
comment 'Table for housing registered peers under this network';
create index registered_peers_registered_index
on registered_peers (registered)
comment 'The Index for the reigstered column of the peer';

View file

@ -0,0 +1,24 @@
create table sessions
(
uuid varchar(36) default uuid() not null comment 'The Unique Primary index for the session UUID'
primary key,
authenticated_peer_uuid varchar(36) null comment 'The peer the session is authenticated as, null if the session isn''t authenticated',
public_key blob not null comment 'The client''s public key provided when creating the session',
state enum ('ACTIVE', 'EXPIRED', 'CLOSED') default 'ACTIVE' not null comment 'The status of the session',
created timestamp default current_timestamp() not null comment 'The Timestamp for when the session was last created',
last_request timestamp null comment 'The Timestamp for when the last request was made using this session',
constraint sessions_uuid_uindex
unique (uuid) comment 'The Unique Primary index for the session UUID',
constraint sessions_registered_peers_uuid_fk
foreign key (authenticated_peer_uuid) references registered_peers (uuid)
on update cascade on delete cascade
);
create index sessions_authenticated_peer_index
on sessions (authenticated_peer_uuid)
comment 'The Index for the authenticated peer column';
create index sessions_created_index
on sessions (created)
comment 'The Index for the created column of the session';