Add friendships and friend_requests database tables

This commit is contained in:
Ethan Girouard 2024-09-28 20:28:00 -04:00
parent bf89838297
commit a83fb9dea5
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146
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! {
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,