From: Chris Fulljames Date: Tue, 18 Mar 2025 00:37:01 +0000 (-0400) Subject: Initial work on new comment schema X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=6e42d3f4fe1072ea116df899a11ac22075ad1c52;p=littlesongplace.git Initial work on new comment schema --- diff --git a/schema.sql b/schema.sql index f05d0c7..b1aa9c8 100644 --- a/schema.sql +++ b/schema.sql @@ -66,5 +66,30 @@ CREATE TABLE song_comment_notifications ( ); CREATE INDEX idx_song_comment_notifications_by_target ON song_comment_notifications(targetuserid); -PRAGMA user_version = 2; +DROP TABLE IF EXISTS playlists; +CREATE TABLE playlists ( + playlistid INTEGER PRIMARY KEY, + created TEXT NOT NULL, + updated TEXT NOT NULL, + userid INTEGER NOT NULL, + name TEXT NOT NULL, + private INTEGER NOT NULL, + + FOREIGN KEY(userid) REFERENCES users(userid) ON DELETE CASCADE +); +CREATE INDEX playlists_by_userid ON playlists(userid); + +DROP TABLE IF EXISTS playlist_songs; +CREATE TABLE playlist_songs ( + playlistid INTEGER NOT NULL, + position INTEGER NOT NULL, + songid INTEGER NOT NULL, + + PRIMARY KEY(playlistid, position), + FOREIGN KEY(playlistid) REFERENCES playlists(playlistid) ON DELETE CASCADE, + FOREIGN KEY(songid) REFERENCES songs(songid) ON DELETE CASCADE +); +CREATE INDEX playlist_songs_by_playlist ON playlist_songs(playlistid); + +PRAGMA user_version = 3; diff --git a/schema_update.sql b/schema_update.sql index 3d065f2..0885301 100644 --- a/schema_update.sql +++ b/schema_update.sql @@ -1,25 +1,40 @@ -CREATE TABLE playlists ( - playlistid INTEGER PRIMARY KEY, - created TEXT NOT NULL, - updated TEXT NOT NULL, - userid INTEGER NOT NULL, - name TEXT NOT NULL, - private INTEGER NOT NULL, +-- Create new comment tables +CREATE TABLE comment_threads ( + threadid INTEGER PRIMARY KEY, + threadtype INTEGER DEFAULT 0, +); +CREATE TABLE comments ( + commentid INTEGER PRIMARY KEY, + threadid INTEGER NOT NULL, + userid INTEGER NOT NULL, + replytoid INTEGER, + created TEXT NOT NULL, + content TEXT NOT NULL, + FOREIGN KEY(threadid) REFERENCES comment_threads(threadid) ON DELETE CASCADE, FOREIGN KEY(userid) REFERENCES users(userid) ON DELETE CASCADE ); -CREATE INDEX playlists_by_userid ON playlists(userid); +CREATE INDEX idx_comments_user ON comments(userid); +CREATE INDEX idx_comments_replyto ON comments(replytoid); +CREATE INDEX idx_comments_time ON comments(created); -CREATE TABLE playlist_songs ( - playlistid INTEGER NOT NULL, - position INTEGER NOT NULL, - songid INTEGER NOT NULL, - - PRIMARY KEY(playlistid, position), - FOREIGN KEY(playlistid) REFERENCES playlists(playlistid) ON DELETE CASCADE, - FOREIGN KEY(songid) REFERENCES songs(songid) ON DELETE CASCADE +CREATE TABLE comment_notifications ( + notificationid INTEGER PRIMARY KEY, + commentid INTEGER NOT NULL, + targetuserid INTEGER NOT NULL, + FOREIGN KEY(commentid) REFERENCES comments(commentid) ON DELETE CASCADE, + FOREIGN KEY(targetuserid) REFERENCES users(userid) ON DELETE CASCADE ); -CREATE INDEX playlist_songs_by_playlist ON playlist_songs(playlistid); +CREATE INDEX idx_comment_notifications_by_target ON comment_notifications(targetuserid); + +-- Add comment thread to songs table +ALTER TABLE songs ADD COLUMN threadid INTEGER; + +-- Add profile comment thread to users table +ALTER TABLE users ADD COLUMN threadid INTEGER; + +-- Add playlist comment thread to playlists table +ALTER TABLE playlists ADD COLUMN threadid INTEGER; -PRAGMA user_version = 3; +PRAGMA user_version = 4;