Create songs table
This commit is contained in:
parent
bf99dac25c
commit
319958f264
2
migrations/2024-02-06-150334_create_songs_table/down.sql
Normal file
2
migrations/2024-02-06-150334_create_songs_table/down.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
DROP TABLE song_artists;
|
||||||
|
DROP TABLE songs;
|
16
migrations/2024-02-06-150334_create_songs_table/up.sql
Normal file
16
migrations/2024-02-06-150334_create_songs_table/up.sql
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
CREATE TABLE songs (
|
||||||
|
id SERIAL PRIMARY KEY UNIQUE NOT NULL,
|
||||||
|
title VARCHAR NOT NULL,
|
||||||
|
album_id INTEGER REFERENCES albums(id),
|
||||||
|
track INTEGER,
|
||||||
|
duration INTEGER NOT NULL,
|
||||||
|
release_date DATE,
|
||||||
|
storage_path VARCHAR NOT NULL,
|
||||||
|
image_path VARCHAR
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE song_artists (
|
||||||
|
song_id INTEGER REFERENCES songs(id) ON DELETE CASCADE NOT NULL,
|
||||||
|
artist_id INTEGER REFERENCES artists(id) ON DELETE CASCADE NOT NULL,
|
||||||
|
PRIMARY KEY (song_id, artist_id)
|
||||||
|
);
|
@ -22,6 +22,26 @@ diesel::table! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
song_artists (song_id, artist_id) {
|
||||||
|
song_id -> Int4,
|
||||||
|
artist_id -> Int4,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
songs (id) {
|
||||||
|
id -> Int4,
|
||||||
|
title -> Varchar,
|
||||||
|
album_id -> Nullable<Int4>,
|
||||||
|
track -> Nullable<Int4>,
|
||||||
|
duration -> Int4,
|
||||||
|
release_date -> Nullable<Date>,
|
||||||
|
storage_path -> Varchar,
|
||||||
|
image_path -> Nullable<Varchar>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
users (id) {
|
users (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
@ -34,10 +54,15 @@ diesel::table! {
|
|||||||
|
|
||||||
diesel::joinable!(album_artists -> albums (album_id));
|
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 -> songs (song_id));
|
||||||
|
diesel::joinable!(songs -> albums (album_id));
|
||||||
|
|
||||||
diesel::allow_tables_to_appear_in_same_query!(
|
diesel::allow_tables_to_appear_in_same_query!(
|
||||||
album_artists,
|
album_artists,
|
||||||
albums,
|
albums,
|
||||||
artists,
|
artists,
|
||||||
|
song_artists,
|
||||||
|
songs,
|
||||||
users,
|
users,
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user