This repository has been archived on 2024-08-23. You can view files and clone it, but cannot push or open issues or pull requests.
project/migrations/0001_initial.up.sql

39 lines
1.3 KiB
MySQL
Raw Normal View History

2024-07-30 17:21:33 +00:00
CREATE EXTENSION IF NOT EXISTS pg_trgm;
2024-06-27 12:04:57 +00:00
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,
2024-07-27 19:08:56 +00:00
permission_type permission NOT NULL,
UNIQUE (user_id, folder_id)
2024-06-27 12:04:57 +00:00
);