Merge pull request 'Implement friends' (#96) from 44-implement-friends into main

Reviewed-on: LibreTunes/LibreTunes#96
This commit is contained in:
Ethan Girouard 2024-09-29 01:15:56 +00:00
commit 236c75492a
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,7 @@
DROP INDEX friendships_friend_2_idx;
DROP INDEX friendships_friend_1_idx;
DROP TABLE friendships;
DROP INDEX incoming_friend_requests_idx;
DROP INDEX outgoing_friend_requests_idx;
DROP TABLE friend_requests;

View File

@ -0,0 +1,19 @@
CREATE TABLE friend_requests (
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
from_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
to_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
PRIMARY KEY (from_id, to_id)
);
CREATE INDEX outgoing_friend_requests_idx ON friend_requests(from_id);
CREATE INDEX incoming_friend_requests_idx ON friend_requests(to_id);
CREATE TABLE friendships (
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
friend_1_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
friend_2_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
PRIMARY KEY (friend_1_id, friend_2_id)
);
CREATE INDEX friendships_friend_1_idx ON friendships(friend_1_id);
CREATE INDEX friendships_friend_2_idx ON friendships(friend_2_id);

View File

@ -23,6 +23,22 @@ diesel::table! {
} }
} }
diesel::table! {
friend_requests (from_id, to_id) {
created_at -> Timestamp,
from_id -> Int4,
to_id -> Int4,
}
}
diesel::table! {
friendships (friend_1_id, friend_2_id) {
created_at -> Timestamp,
friend_1_id -> Int4,
friend_2_id -> Int4,
}
}
diesel::table! { diesel::table! {
song_artists (song_id, artist_id) { song_artists (song_id, artist_id) {
song_id -> Int4, song_id -> Int4,
@ -82,6 +98,8 @@ diesel::allow_tables_to_appear_in_same_query!(
album_artists, album_artists,
albums, albums,
artists, artists,
friend_requests,
friendships,
song_artists, song_artists,
song_dislikes, song_dislikes,
song_likes, song_likes,