Add DB table for song history

This commit is contained in:
Ethan Girouard 2024-05-19 12:44:47 -04:00
parent 7bcb5f8c04
commit 81f0b9310f
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146
3 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,2 @@
DROP INDEX song_history_user_id_idx;
DROP TABLE song_history;

View File

@ -0,0 +1,8 @@
CREATE TABLE song_history (
id SERIAL PRIMARY KEY UNIQUE NOT NULL,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
date TIMESTAMP NOT NULL DEFAULT NOW(),
song_id INTEGER REFERENCES songs(id) ON DELETE CASCADE NOT NULL
);
CREATE INDEX song_history_user_id_idx ON song_history(user_id);

View File

@ -30,6 +30,15 @@ diesel::table! {
} }
} }
diesel::table! {
song_history (id) {
id -> Int4,
user_id -> Int4,
date -> Timestamp,
song_id -> Int4,
}
}
diesel::table! { diesel::table! {
songs (id) { songs (id) {
id -> Int4, id -> Int4,
@ -57,6 +66,8 @@ diesel::joinable!(album_artists -> albums (album_id));
diesel::joinable!(album_artists -> artists (artist_id)); diesel::joinable!(album_artists -> artists (artist_id));
diesel::joinable!(song_artists -> artists (artist_id)); diesel::joinable!(song_artists -> artists (artist_id));
diesel::joinable!(song_artists -> songs (song_id)); diesel::joinable!(song_artists -> songs (song_id));
diesel::joinable!(song_history -> songs (song_id));
diesel::joinable!(song_history -> users (user_id));
diesel::joinable!(songs -> albums (album_id)); diesel::joinable!(songs -> albums (album_id));
diesel::allow_tables_to_appear_in_same_query!( diesel::allow_tables_to_appear_in_same_query!(
@ -64,6 +75,7 @@ diesel::allow_tables_to_appear_in_same_query!(
albums, albums,
artists, artists,
song_artists, song_artists,
song_history,
songs, songs,
users, users,
); );