Merge pull request '111-create-playlist-database-tables' (#137) from 111-create-playlist-database-tables into main
Reviewed-on: LibreTunes/LibreTunes#137 Reviewed-by: Ethan Girouard <ethan@girouard.com>
This commit is contained in:
commit
d09060959a
@ -0,0 +1,5 @@
|
||||
DROP INDEX playlists_owner_idx;
|
||||
DROP TABLE playlists;
|
||||
|
||||
DROP INDEX playlist_songs_playlist_idx;
|
||||
DROP TABLE playlist_songs;
|
17
migrations/2024-10-22-212759_create_playlist_tables/up.sql
Normal file
17
migrations/2024-10-22-212759_create_playlist_tables/up.sql
Normal file
@ -0,0 +1,17 @@
|
||||
CREATE TABLE playlists (
|
||||
id SERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
owner_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
|
||||
name TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX playlists_owner_idx ON playlists(owner_id);
|
||||
|
||||
CREATE TABLE playlist_songs (
|
||||
playlist_id INTEGER REFERENCES playlists(id) ON DELETE CASCADE NOT NULL,
|
||||
song_id INTEGER REFERENCES songs(id) ON DELETE CASCADE NOT NULL,
|
||||
PRIMARY KEY (playlist_id, song_id)
|
||||
);
|
||||
|
||||
CREATE INDEX playlist_songs_playlist_idx ON playlist_songs(playlist_id);
|
@ -625,3 +625,24 @@ pub struct HistoryEntry {
|
||||
/// The id of the song that was listened to
|
||||
pub song_id: i32,
|
||||
}
|
||||
|
||||
/// Model for a playlist
|
||||
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable))]
|
||||
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::playlists))]
|
||||
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Playlist {
|
||||
/// A unique id for the playlist
|
||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
||||
pub id: Option<i32>,
|
||||
/// The time the playlist was created
|
||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = NaiveDateTime))]
|
||||
pub created_at: Option<NaiveDateTime>,
|
||||
/// The time the playlist was last updated
|
||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = NaiveDateTime))]
|
||||
pub updated_at: Option<NaiveDateTime>,
|
||||
/// The id of the user who owns the playlist
|
||||
pub owner_id: i32,
|
||||
/// The name of the playlist
|
||||
pub name: String,
|
||||
}
|
||||
|
@ -39,6 +39,23 @@ diesel::table! {
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
playlist_songs (playlist_id, song_id) {
|
||||
playlist_id -> Int4,
|
||||
song_id -> Int4,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
playlists (id) {
|
||||
id -> Int4,
|
||||
created_at -> Timestamp,
|
||||
updated_at -> Timestamp,
|
||||
owner_id -> Int4,
|
||||
name -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
song_artists (song_id, artist_id) {
|
||||
song_id -> Int4,
|
||||
@ -95,6 +112,9 @@ diesel::table! {
|
||||
|
||||
diesel::joinable!(album_artists -> albums (album_id));
|
||||
diesel::joinable!(album_artists -> artists (artist_id));
|
||||
diesel::joinable!(playlist_songs -> playlists (playlist_id));
|
||||
diesel::joinable!(playlist_songs -> songs (song_id));
|
||||
diesel::joinable!(playlists -> users (owner_id));
|
||||
diesel::joinable!(song_artists -> artists (artist_id));
|
||||
diesel::joinable!(song_artists -> songs (song_id));
|
||||
diesel::joinable!(song_dislikes -> songs (song_id));
|
||||
@ -111,6 +131,8 @@ diesel::allow_tables_to_appear_in_same_query!(
|
||||
artists,
|
||||
friend_requests,
|
||||
friendships,
|
||||
playlist_songs,
|
||||
playlists,
|
||||
song_artists,
|
||||
song_dislikes,
|
||||
song_history,
|
||||
|
Loading…
x
Reference in New Issue
Block a user