migrations: more database migrations for various database fixes

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I8567eec6980b2b5453687bcbd07a61206a6a6964
This commit is contained in:
raf 2026-02-03 10:24:35 +03:00
commit 56d44e120a
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
8 changed files with 418 additions and 0 deletions

View file

@ -0,0 +1,35 @@
-- Users table
CREATE TABLE users (
id UUID PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
role JSONB NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
);
-- User profiles table
CREATE TABLE user_profiles (
user_id UUID PRIMARY KEY,
avatar_path TEXT,
bio TEXT,
preferences_json JSONB NOT NULL DEFAULT '{}',
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- User library access table
CREATE TABLE user_libraries (
user_id UUID NOT NULL,
root_path TEXT NOT NULL,
permission JSONB NOT NULL,
granted_at TIMESTAMP WITH TIME ZONE NOT NULL,
PRIMARY KEY (user_id, root_path),
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- Indexes for efficient lookups
CREATE INDEX idx_users_username ON users(username);
CREATE INDEX idx_user_libraries_user_id ON user_libraries(user_id);
CREATE INDEX idx_user_libraries_root_path ON user_libraries(root_path);