Initial commit

This commit is contained in:
2024-06-27 15:04:57 +03:00
commit e8114c515d
40 changed files with 4180 additions and 0 deletions

View File

@ -0,0 +1,9 @@
DROP TABLE permissions;
DROP TABLE files;
DROP TABLE folders;
DROP TABLE users;
DROP TYPE permission;

View File

@ -0,0 +1,36 @@
CREATE TABLE
users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE
);
CREATE TABLE
folders (
folder_id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
parent_folder_id UUID REFERENCES folders (folder_id) ON DELETE CASCADE DEFAULT null,
owner_id INT REFERENCES users (user_id) ON DELETE CASCADE NOT NULL,
folder_name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE TABLE
files (
file_id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
folder_id UUID REFERENCES folders (folder_id) ON DELETE CASCADE NOT NULL,
file_name VARCHAR(255) NOT NULL,
file_size BIGINT NOT NULL,
sha512 BYTEA NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE TYPE permission AS ENUM ('read', 'write', 'manage');
CREATE TABLE
permissions (
permission_id SERIAL PRIMARY KEY,
user_id INT REFERENCES users (user_id) ON DELETE CASCADE NOT NULL,
folder_id UUID REFERENCES folders (folder_id) ON DELETE CASCADE,
permission_type permission NOT NULL
);