diff --git a/migrations/2024-05-19-163229_add_song_history/down.sql b/migrations/2024-05-19-163229_add_song_history/down.sql new file mode 100644 index 0000000..4c1a657 --- /dev/null +++ b/migrations/2024-05-19-163229_add_song_history/down.sql @@ -0,0 +1,2 @@ +DROP INDEX song_history_user_id_idx; +DROP TABLE song_history; diff --git a/migrations/2024-05-19-163229_add_song_history/up.sql b/migrations/2024-05-19-163229_add_song_history/up.sql new file mode 100644 index 0000000..42ce503 --- /dev/null +++ b/migrations/2024-05-19-163229_add_song_history/up.sql @@ -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); diff --git a/src/schema.rs b/src/schema.rs index 97de324..986006f 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -30,6 +30,15 @@ diesel::table! { } } +diesel::table! { + song_history (id) { + id -> Int4, + user_id -> Int4, + date -> Timestamp, + song_id -> Int4, + } +} + diesel::table! { songs (id) { id -> Int4, @@ -57,6 +66,8 @@ diesel::joinable!(album_artists -> albums (album_id)); diesel::joinable!(album_artists -> artists (artist_id)); diesel::joinable!(song_artists -> artists (artist_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::allow_tables_to_appear_in_same_query!( @@ -64,6 +75,7 @@ diesel::allow_tables_to_appear_in_same_query!( albums, artists, song_artists, + song_history, songs, users, );