diff --git a/migrations/2024-05-20-154208_add_friends/down.sql b/migrations/2024-05-20-154208_add_friends/down.sql new file mode 100644 index 0000000..be4a2a9 --- /dev/null +++ b/migrations/2024-05-20-154208_add_friends/down.sql @@ -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; diff --git a/migrations/2024-05-20-154208_add_friends/up.sql b/migrations/2024-05-20-154208_add_friends/up.sql new file mode 100644 index 0000000..421f223 --- /dev/null +++ b/migrations/2024-05-20-154208_add_friends/up.sql @@ -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); diff --git a/src/schema.rs b/src/schema.rs index 1fc0d64..6d5cc2c 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -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! { song_artists (song_id, artist_id) { song_id -> Int4, @@ -82,6 +98,8 @@ diesel::allow_tables_to_appear_in_same_query!( album_artists, albums, artists, + friend_requests, + friendships, song_artists, song_dislikes, song_likes,