-- Users as auth data create table if not exists users ( id bigserial primary key, username text default null, login text not null unique, password bytea not null, created_at timestamptz default current_timestamp, updated_at timestamptz default current_timestamp ); alter table users add constraint users_username_len check(length(username) > 250) not valid; alter table users add constraint users_login_len check(length(username) > 250) not valid; create index idx_users_login on users (login); create index idx_users_username on users (username); -- Sessions and auth data create table sessions ( id bigserial primary key, session_token varchar(200) not null unique, csrf_token varchar(200) not null unique, user_id bigserial references users(id), created_at timestamp default current_timestamp, expired_at timestamp not null ); create index if not exists idx_sessions_session_token_csrf_token on sessions (session_token, csrf_token); -- Files create table files_metadata ( id bigserial primary key, name text not null, fslink text not null, size bigint not null, ext text not null, owner_id bigint not null, parent_dir bigint not null, created_at timestamptz default current_timestamp, updated_at timestamptz default null, deleted_at timestamptz default null ); create index idx_fm_owner_id on files_metadata(owner_id); create index idx_fm_owner_id_parent_dir on files_metadata(owner_id, parent_dir); create table directories ( id bigserial primary key, name text not null, owner_id bigint not null, parent_dir bigint not null, created_at timestamptz default current_timestamp, updated_at timestamptz default null, deleted_at timestamptz default null ); create index idx_directories_owner_id_parent_dir on directories(owner_id, parent_dir); create table directory_users_access ( id bigserial primary key, dir_id bigint not null, user_id bigint not null, assess_flag integer, created_at timestamptz default current_timestamp, updated_at timestamptz default null ); create index idx_dua_owner_id_parent_dir on directories(owner_id, parent_dir);