From 9c4d3a719733bdcad13bdd862a90f5363aaabf4e Mon Sep 17 00:00:00 2001 From: Sundog Date: Thu, 19 Oct 2023 14:57:03 -0400 Subject: [PATCH] updates MODELS and SCHEMAS --- MODELS.md | 37 ++++++++- SCHEMA.md | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+), 4 deletions(-) diff --git a/MODELS.md b/MODELS.md index 53e06ca..8e7dbcb 100644 --- a/MODELS.md +++ b/MODELS.md @@ -21,6 +21,9 @@ struct Person { name: String, handle: Option, email: Option>, + avatar: Option, + cover: Option, + bio: Option, is_active: bool, is_blocked: bool, created_at: chrono::DateTime, @@ -240,8 +243,8 @@ struct PlaylistId { struct Playlist { id: PlaylistId, title: String, - description: String, - created_by: String, + description: Option, + created_by: PersonId, created_at: chrono::DateTime, modified_at: chrono::DateTime, deleted_at: Option @@ -313,14 +316,40 @@ struct Comment { target_id: CommentTargetId, created_by: PersonId, created_at: chrono::DateTime, - modified_at: chrono::DateTime, - deleted_at: Option + modified_by: Option, + modified_at: Option, + deleted_by: Option, + deleted_at: Option, is_public: bool, is_approved: bool, in_reply_to: Option, } ``` +# Image + +An Image represents an image file that a Person wants to reference from a Label, an Artist, an Album, a Track, a Playlist, or an Article. + +``` rust +struct ImageId { + id: String, +} +struct Image { + id: ImageId, + path: String, + width: usize, + height: usize, + alt_text: String, + is_public: bool, + created_by: PersonId, + created_at: chrono::DateTime, + modified_by: PersonId, + modified_at: chrono::DateTime, + deleted_by: Option, + deleted_at: Option, +} +``` + # Collection A Collection represents one or more Albums and/or Tracks that are offered together as a package for Purchase diff --git a/SCHEMA.md b/SCHEMA.md index 5d76d90..d108211 100644 --- a/SCHEMA.md +++ b/SCHEMA.md @@ -13,6 +13,9 @@ CREATE TABLE Persons ( remote_id TEXT, /* field to store an arbitrary remote identifier for this Person if they are not local */ name TEXT, /* "real" name */ handle TEXT, /* also commonly refered to as 'display_name' or 'screen_name', optional (if missing, name will be used as handle) */ + avatar TEXT, /* optional URL to Person's avatar image / profile pic */ + cover TEXT, /* optional URL to Person's cover image / header image */ + bio TEXT, /* optional biographical text provided by Person */ is_active INTEGER DEFAULT (1), /* bool, default true */ is_blocked INTEGER DEFAULT (0), /* bool, default false */ created_at INTEGER, /* timestamp */ @@ -330,23 +333,248 @@ CREATE INDEX Albums_deleted_at_IDX ON Albums (deleted_at); ``` # AlbumArtists +The AlbumArtists table will be a one-to-many lookup table mapping Artists to a particular Album. + +``` sql +CREATE TABLE AlbumArtists ( + album_id TEXT(36), + artist_id TEXT(36), + is_primary INTEGER DEFAULT (0), + CONSTRAINT AlbumArtists_PK PRIMARY KEY (album_id,artist_id), + CONSTRAINT AlbumArtists_FK FOREIGN KEY (album_id) REFERENCES Albums(id) ON DELETE CASCADE, + CONSTRAINT AlbumArtists_FK_1 FOREIGN KEY (artist_id) REFERENCES Artists(id) ON DELETE CASCADE +); +CREATE INDEX AlbumArtists_is_primary_IDX ON AlbumArtists (is_primary); +CREATE INDEX AlbumArtists_album_id_IDX ON AlbumArtists (album_id); +CREATE INDEX AlbumArtists_artist_id_IDX ON AlbumArtists (artist_id); +``` # AlbumTags +The AlbumTags table will contain Tags that have been assigned to an Album. + +``` sql +CREATE TABLE AlbumTags ( + album_id TEXT(36), + tag_id TEXT(36), + is_approved INTEGER DEFAULT (0), + CONSTRAINT AlbumTags_PK PRIMARY KEY (album_id,tag_id), + CONSTRAINT AlbumTags_FK FOREIGN KEY (album_id) REFERENCES Albums(id) ON DELETE CASCADE, + CONSTRAINT AlbumTags_FK_1 FOREIGN KEY (tag_id) REFERENCES Tags(id) ON DELETE CASCADE +); +CREATE INDEX AlbumTags_is_approved_IDX ON AlbumTags (is_approved); +CREATE INDEX AlbumTags_album_id_IDX ON AlbumTags (album_id); +CREATE INDEX AlbumTags_tag_id_IDX ON AlbumTags (tag_id); +``` + +# AlbumTracks +The AlbumTracks table will be a many-to-many lookup table mapping Tracks to Albums + +``` sql +CREATE TABLE AlbumTracks ( + album_id TEXT(36), + track_id TEXT(36), + track_number INTEGER, + CONSTRAINT AlbumTracks_PK PRIMARY KEY (album_id,track_id), + CONSTRAINT AlbumTracks_FK FOREIGN KEY (album_id) REFERENCES Albums(id) ON DELETE CASCADE, + CONSTRAINT AlbumTracks_FK_1 FOREIGN KEY (track_id) REFERENCES Tracks(id) ON DELETE CASCADE +); +CREATE INDEX AlbumTracks_track_number_IDX ON AlbumTracks (track_number); +CREATE INDEX AlbumTracks_album_id_IDX ON AlbumTracks (album_id); +CREATE INDEX AlbumTracks_track_id_IDX ON AlbumTracks (track_id); +``` # Playlists +The Playlists table will contain Playlists! + +``` sql +CREATE TABLE Playlists ( + id TEXT(36), + title TEXT, + description TEXT, + created_by TEXT(36), + created_at INTEGER, + modified_at INTEGER, + deleted_at INTEGER, + is_public INTEGER DEFAULT (1), + CONSTRAINT Playlists_PK PRIMARY KEY (id), + CONSTRAINT Playlists_FK FOREIGN KEY (created_by) REFERENCES Persons(id) +); +CREATE INDEX Playlists_title_IDX ON Playlists (title); +CREATE INDEX Playlists_description_IDX ON Playlists (description); +CREATE INDEX Playlists_created_by_IDX ON Playlists (created_by); +CREATE INDEX Playlists_created_at_IDX ON Playlists (created_at); +CREATE INDEX Playlists_modified_at_IDX ON Playlists (modified_at); +CREATE INDEX Playlists_deleted_at_IDX ON Playlists (deleted_at); +CREATE INDEX Playlists_is_public_IDX ON Playlists (is_public); +``` # PlaylistTracks +The PlaylistTracks table will be a many-to-many lookup table mapping Tracks to Playlists + +``` sql +CREATE TABLE PlaylistTracks ( + playlist_track_id TEXT(36), + playlist_id TEXT(36), + track_id TEXT, + track_number INTEGER, + CONSTRAINT PlaylistTracks_PK PRIMARY KEY (playlist_track_id), + CONSTRAINT PlaylistTracks_FK FOREIGN KEY (playlist_id) REFERENCES Playlists(id) ON DELETE CASCADE, + CONSTRAINT PlaylistTracks_FK_1 FOREIGN KEY (track_id) REFERENCES Tracks(id) ON DELETE CASCADE +); +CREATE INDEX PlaylistTracks_track_number_IDX ON PlaylistTracks (track_number); +CREATE INDEX PlaylistTracks_playlist_id_IDX ON PlaylistTracks (playlist_id); +CREATE INDEX PlaylistTracks_track_id_IDX ON PlaylistTracks (track_id); +``` # PlaylistTags +The PlaylistTags table will contain Tags that have been assigned to a Playlist. + +``` sql +CREATE TABLE PlaylistTags ( + playlist_id TEXT(36), + tag_id TEXT(36), + is_approved INTEGER DEFAULT (0), + CONSTRAINT PlaylistTags_PK PRIMARY KEY (playlist_id,tag_id), + CONSTRAINT PlaylistTags_FK FOREIGN KEY (playlist_id) REFERENCES Playlists(id) ON DELETE CASCADE, + CONSTRAINT PlaylistTags_FK_1 FOREIGN KEY (tag_id) REFERENCES Tags(id) ON DELETE CASCADE +); +CREATE INDEX PlaylistTags_is_approved_IDX ON PlaylistTags (is_approved); +CREATE INDEX PlaylistTags_playlist_id_IDX ON PlaylistTags (playlist_id); +CREATE INDEX PlaylistTags_tag_id_IDX ON PlaylistTags (tag_id); +``` # Comments +The Comments table will contain Comments! + +``` sql +CREATE TABLE Comments ( + id TEXT(36), + body TEXT, + created_by TEXT(36), + created_at INTEGER, + modified_by TEXT(36), + modified_at INTEGER, + deleted_by TEXT(36), + deleted_at INTEGER, + is_public INTEGER DEFAULT (1), + is_approved INTEGER DEFAULT (0), + in_reply_to TEXT(36), + CONSTRAINT Comments_PK PRIMARY KEY (id), + CONSTRAINT Comments_FK FOREIGN KEY (created_by) REFERENCES Persons(id), + CONSTRAINT Comments_FK_1 FOREIGN KEY (modified_by) REFERENCES Persons(id), + CONSTRAINT Comments_FK_2 FOREIGN KEY (deleted_by) REFERENCES Persons(id) +); +CREATE INDEX Comments_body_IDX ON Comments (body); +CREATE INDEX Comments_created_at_IDX ON Comments (created_at); +CREATE INDEX Comments_modified_at_IDX ON Comments (modified_at); +CREATE INDEX Comments_deleted_at_IDX ON Comments (deleted_at); +CREATE INDEX Comments_is_public_IDX ON Comments (is_public); +CREATE INDEX Comments_is_approved_IDX ON Comments (is_approved); +CREATE INDEX Comments_in_reply_to_IDX ON Comments (in_reply_to); +``` # LabelComments +The LabelComments table will relate Comments to the Label they are about, if pertinent. + +``` sql +CREATE TABLE LabelComments ( + label_id TEXT(36), + comment_id TEXT(36), + CONSTRAINT LabelComments_PK PRIMARY KEY (label_id,comment_id), + CONSTRAINT LabelComments_FK FOREIGN KEY (label_id) REFERENCES Labels(id) ON DELETE CASCADE, + CONSTRAINT LabelComments_FK_1 FOREIGN KEY (comment_id) REFERENCES Comments(id) ON DELETE CASCADE +); +CREATE INDEX LabelComments_label_id_IDX ON LabelComments (label_id); +CREATE INDEX LabelComments_comment_id_IDX ON LabelComments (comment_id); +``` # ArtistComments +The ArtistComments table will relate Comments to the Artist they are about, if pertinent. + +``` sql +CREATE TABLE ArtistComments ( + artist_id TEXT(36), + comment_id TEXT(36), + CONSTRAINT ArtistComments_PK PRIMARY KEY (artist_id,comment_id), + CONSTRAINT ArtistComments_FK FOREIGN KEY (artist_id) REFERENCES Artists(id) ON DELETE CASCADE, + CONSTRAINT ArtistComments_FK_1 FOREIGN KEY (comment_id) REFERENCES Comments(id) ON DELETE CASCADE +); +CREATE INDEX ArtistComments_artist_id_IDX ON ArtistComments (artist_id); +CREATE INDEX ArtistComments_comment_id_IDX ON ArtistComments (comment_id); +``` # TrackComments +The TrackComments table will relate Comments to the Track they are about, if pertinent. + +``` sql +CREATE TABLE TrackComments ( + track_id TEXT(36), + comment_id TEXT(36), + CONSTRAINT TrackComments_PK PRIMARY KEY (track_id,comment_id), + CONSTRAINT TrackComments_FK FOREIGN KEY (track_id) REFERENCES Tracks(id) ON DELETE CASCADE, + CONSTRAINT TrackComments_FK_1 FOREIGN KEY (comment_id) REFERENCES Comments(id) ON DELETE CASCADE +); +CREATE INDEX TrackComments_track_id_IDX ON TrackComments (track_id); +CREATE INDEX TrackComments_comment_id_IDX ON TrackComments (comment_id); +``` # AlbumComments +The AlbumComments table will relate Comments to the Album they are about, if pertinent. + +``` sql +CREATE TABLE AlbumComments ( + album_id TEXT(36), + comment_id TEXT(36), + CONSTRAINT AlbumComments_PK PRIMARY KEY (album_id,comment_id), + CONSTRAINT AlbumComments_FK FOREIGN KEY (album_id) REFERENCES Albums(id) ON DELETE CASCADE, + CONSTRAINT AlbumComments_FK_1 FOREIGN KEY (comment_id) REFERENCES Comments(id) ON DELETE CASCADE +); +CREATE INDEX AlbumComments_album_id_IDX ON AlbumComments (album_id); +CREATE INDEX AlbumComments_comment_id_IDX ON AlbumComments (comment_id); +``` # PlaylistComments +The PlaylistComments table will relate Comments to the Playlist they are about, if pertinent. + +``` sql +CREATE TABLE PlaylistComments ( + playlist_id TEXT(36), + comment_id TEXT(36), + CONSTRAINT PlaylistComments_PK PRIMARY KEY (playlist_id,comment_id), + CONSTRAINT PlaylistComments_FK FOREIGN KEY (playlist_id) REFERENCES Playlists(id) ON DELETE CASCADE, + CONSTRAINT PlaylistComments_FK_1 FOREIGN KEY (comment_id) REFERENCES Comments(id) ON DELETE CASCADE +); +CREATE INDEX PlaylistComments_playlist_id_IDX ON PlaylistComments (playlist_id); +CREATE INDEX PlaylistComments_comment_id_IDX ON PlaylistComments (comment_id); +``` + +# LabelImages + +# ArtistImages + +# TrackImages + +# AlbumImages + +# PlaylistImages + +# LabelVideos + +# ArtistVideos + +# TrackVideos + +# AlbumVideos + +# ArtistContacts + +# Articles + +# ArticleTags + +# ArticleImages + +# ArticleVideos + +# ArticleComments +