]> littlesong.place Git - littlesongplace.git/commitdiff
Initial work on new comment schema
authorChris Fulljames <christianfulljames@gmail.com>
Tue, 18 Mar 2025 00:37:01 +0000 (20:37 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Tue, 18 Mar 2025 00:37:01 +0000 (20:37 -0400)
schema.sql
schema_update.sql

index f05d0c75b9fbb6eff5ff0dcfd47a6fa4d8d95042..b1aa9c87bee6dbe048702ac1409b4c8510d35d48 100644 (file)
@@ -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;
 
index 3d065f29263e39712ea3c97669f5a62fb9a24e6c..088530184c511128e05ed9f3312dd0e03fee4da0 100644 (file)
@@ -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;