Create playlist database migration
This commit is contained in:
parent
36e7a5827b
commit
81b1490cce
@ -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);
|
@ -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