refactor: reorganize project structure and update configurations

- Move migrations/ to database/schema/ for clarity on database schema definitions
- Move sqlc.yaml to internal/database/ to group with database code
- Move static/ to cmd/server/static/ to co-locate with server
- Update all configuration files and documentation
- Follow Go project conventions for better organization
This commit is contained in:
2026-01-24 23:40:31 -05:00
parent 8a951fb242
commit 08e80ae84b
34 changed files with 532 additions and 104 deletions
+44
View File
@@ -0,0 +1,44 @@
-- Create users table
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) UNIQUE NOT NULL,
username VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
theme VARCHAR(50) DEFAULT 'tokyo-night',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create ebooks table
CREATE TABLE ebooks (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
author VARCHAR(255),
isbn VARCHAR(13),
description TEXT,
file_path VARCHAR(500) NOT NULL,
file_size BIGINT,
mime_type VARCHAR(100),
cover_image_path VARCHAR(500),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create reading_progress table
CREATE TABLE reading_progress (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
ebook_id UUID NOT NULL REFERENCES ebooks(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
current_page INTEGER DEFAULT 0,
total_pages INTEGER,
last_read_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(ebook_id, user_id)
);
-- Create indexes
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_username ON users(username);
CREATE INDEX idx_ebooks_title ON ebooks(title);
CREATE INDEX idx_ebooks_author ON ebooks(author);
CREATE INDEX idx_reading_progress_ebook_id ON reading_progress(ebook_id);
CREATE INDEX idx_reading_progress_user_id ON reading_progress(user_id);
+14
View File
@@ -0,0 +1,14 @@
-- Add ebook ratings functionality
CREATE TABLE ebook_ratings (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
ebook_id UUID NOT NULL REFERENCES ebooks(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
rating INTEGER NOT NULL CHECK (rating >= 1 AND rating <= 5),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(ebook_id, user_id)
);
-- Create indexes for better query performance
CREATE INDEX idx_ebook_ratings_ebook_id ON ebook_ratings(ebook_id);
CREATE INDEX idx_ebook_ratings_user_id ON ebook_ratings(user_id);
@@ -0,0 +1,8 @@
-- Add additional metadata fields to ebooks table
ALTER TABLE ebooks ADD COLUMN series VARCHAR(255);
ALTER TABLE ebooks ADD COLUMN series_number INTEGER;
ALTER TABLE ebooks ADD COLUMN tags TEXT;
ALTER TABLE ebooks ADD COLUMN asin VARCHAR(20);
ALTER TABLE ebooks ADD COLUMN date_published DATE;
ALTER TABLE ebooks ADD COLUMN publisher VARCHAR(255);
ALTER TABLE ebooks ADD COLUMN contributors TEXT;
@@ -0,0 +1,2 @@
-- Add ebook_folder_path to users table
ALTER TABLE users ADD COLUMN ebook_folder_path VARCHAR(500);
@@ -0,0 +1,11 @@
-- Create user_ebook_folders table for multiple folders per user
CREATE TABLE user_ebook_folders (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
folder_path VARCHAR(500) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(user_id, folder_path)
);
-- Create index for faster lookups
CREATE INDEX idx_user_ebook_folders_user_id ON user_ebook_folders(user_id);
@@ -0,0 +1,2 @@
-- Drop the old ebook_folder_path column from users table
ALTER TABLE users DROP COLUMN IF EXISTS ebook_folder_path;
@@ -0,0 +1,3 @@
-- Add scan settings to users table
ALTER TABLE users ADD COLUMN scan_frequency_minutes INTEGER DEFAULT 60;
ALTER TABLE users ADD COLUMN auto_scan_enabled BOOLEAN DEFAULT true;
@@ -0,0 +1,3 @@
-- Add first and last name to users table
ALTER TABLE users ADD COLUMN first_name VARCHAR(255);
ALTER TABLE users ADD COLUMN last_name VARCHAR(255);
@@ -0,0 +1,15 @@
-- Normalize existing folder paths in user_ebook_folders table
-- This script will clean up inconsistent path formatting
UPDATE user_ebook_folders
SET folder_path = REPLACE(REPLACE(folder_path, '\\', '/'), '//', '/')
WHERE folder_path LIKE '%\\%' OR folder_path LIKE '%//%';
-- Remove trailing slashes from non-root paths
UPDATE user_ebook_folders
SET folder_path = CASE
WHEN folder_path = '/' THEN '/'
WHEN RIGHT(folder_path, 1) = '/' THEN LEFT(folder_path, LENGTH(folder_path) - 1)
ELSE folder_path
END
WHERE folder_path != '/' AND RIGHT(folder_path, 1) = '/';