added schema.sql file
This commit is contained in:
parent
c7156f7aab
commit
911a827308
@ -1,29 +0,0 @@
|
|||||||
-- +goose Up
|
|
||||||
-- +goose StatementBegin
|
|
||||||
SELECT 'up SQL query';
|
|
||||||
|
|
||||||
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 CONCURRENTLY idx_users_login ON
|
|
||||||
users (login);
|
|
||||||
CREATE INDEX CONCURRENTLY idx_users_username ON
|
|
||||||
users (username);
|
|
||||||
-- +goose StatementEnd
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
-- +goose StatementBegin
|
|
||||||
SELECT 'down SQL query';
|
|
||||||
DROP INDEX CONCURRENTLY IF EXISTS idx_users_login;
|
|
||||||
DROP INDEX CONCURRENTLY IF EXISTS idx_users_username;
|
|
||||||
DROP TABLE IF EXISTS users;
|
|
||||||
-- +goose StatementEnd
|
|
@ -1,26 +0,0 @@
|
|||||||
-- +goose Up
|
|
||||||
-- +goose StatementBegin
|
|
||||||
SELECT 'up SQL query';
|
|
||||||
|
|
||||||
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 concurrently if not exists idx_sessions_session_token_csrf_token
|
|
||||||
on sessions (session_token, csrf_token);
|
|
||||||
|
|
||||||
-- +goose StatementEnd
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
-- +goose StatementBegin
|
|
||||||
SELECT 'down SQL query';
|
|
||||||
|
|
||||||
drop index concurrently idx_sessions_session_token_csrf_token;
|
|
||||||
drop table sessions;
|
|
||||||
|
|
||||||
-- +goose StatementEnd
|
|
@ -1,13 +0,0 @@
|
|||||||
-- +goose Up
|
|
||||||
-- +goose StatementBegin
|
|
||||||
SELECT 'up SQL query';
|
|
||||||
|
|
||||||
create table files_meta (
|
|
||||||
id bigserial primary key
|
|
||||||
);
|
|
||||||
-- +goose StatementEnd
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
-- +goose StatementBegin
|
|
||||||
SELECT 'down SQL query';
|
|
||||||
-- +goose StatementEnd
|
|
76
schema.sql
Normal file
76
schema.sql
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
-- 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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user