server and web app

This commit is contained in:
2026-05-31 23:08:53 -04:00
parent 438b3b29a2
commit b3364447a1
24 changed files with 2318 additions and 153 deletions

View File

@@ -0,0 +1,11 @@
DROP INDEX IF EXISTS idx_watchers_folder;
DROP INDEX IF EXISTS idx_watchers_document;
DROP TABLE IF EXISTS watchers;
DROP INDEX IF EXISTS idx_notifications_created_at;
DROP INDEX IF EXISTS idx_notifications_unread;
DROP INDEX IF EXISTS idx_notifications_user;
DROP TABLE IF EXISTS notifications;
DROP INDEX IF EXISTS idx_comments_author;
DROP INDEX IF EXISTS idx_comments_parent;
DROP INDEX IF EXISTS idx_comments_document;
DROP TABLE IF EXISTS comments;

View File

@@ -0,0 +1,44 @@
CREATE TABLE IF NOT EXISTS comments (
id TEXT PRIMARY KEY,
document_id TEXT NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
version_hash TEXT NOT NULL,
parent_id TEXT REFERENCES comments(id) ON DELETE CASCADE,
author_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
content TEXT NOT NULL,
anchor_hash TEXT,
anchor_line INTEGER,
created_at TEXT NOT NULL,
resolved_at TEXT,
resolved_by TEXT REFERENCES users(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS idx_comments_document ON comments(document_id);
CREATE INDEX IF NOT EXISTS idx_comments_parent ON comments(parent_id);
CREATE INDEX IF NOT EXISTS idx_comments_author ON comments(author_id);
CREATE TABLE IF NOT EXISTS notifications (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
type TEXT NOT NULL CHECK(type IN ('file_changed', 'comment', 'mention', 'conflict')),
resource_type TEXT NOT NULL,
resource_id TEXT NOT NULL,
message TEXT NOT NULL,
read_at TEXT,
emailed_at TEXT,
created_at TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_notifications_user ON notifications(user_id);
CREATE INDEX IF NOT EXISTS idx_notifications_unread ON notifications(user_id, read_at) WHERE read_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_notifications_created_at ON notifications(created_at);
CREATE TABLE IF NOT EXISTS watchers (
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
document_id TEXT REFERENCES documents(id) ON DELETE CASCADE,
folder_path TEXT,
created_at TEXT NOT NULL,
PRIMARY KEY (user_id, document_id, folder_path)
);
CREATE INDEX IF NOT EXISTS idx_watchers_document ON watchers(document_id);
CREATE INDEX IF NOT EXISTS idx_watchers_folder ON watchers(folder_path);