This database schema is designed to support a social media platform resembling Instagram. It includes tables for users, user details, follow relationships, messages, posts, comments, saved posts, and likes.
Link to db diagram: https://drawsql.app/teams/dias-3/diagrams/social-media
- Database endpoint:
social-media-db.c7oegqky2sza.eu-north-1.rds.amazonaws.com
- Port:
5432
- Username:
postgres
- Password:
Eb00ktash
- I have created types, tables, and trigger functions in
create_tables.sql
. - I have inserted data into each table to simulate real-life social media interactions using
inserting_real_data.sql
. - I have written some useful testing queries to assess the system's functionality. (
testing_queries.sql
)
-
Using a PostgreSQL Client:
- Download and install a PostgreSQL client such as pgAdmin, DBeaver, DataGrip or psql.
- Open the client and create a new connection.
- Enter the provided endpoint, port, username, and password when prompted.
- Connect to the database.
-
Using Command Line (psql):
- Open a terminal or command prompt.
- Use the following command to connect:
psql -h social-media-db.c7oegqky2sza.eu-north-1.rds.amazonaws.com -p 5432 -U postgres -W
- Enter the password when prompted.
Stores user account information including username, email, and password.
Stores additional user profile information such as first name, last name, and profile picture.
Manages user follow relationships with fields like following_user_id, followed_user_id, and status.
Stores messages between users with sender_id, receiver_id, content, etc.
Defines types of posts like 'story', 'profile', etc.
Stores post information including caption, post_type_id, user_id, etc.
Stores media files related to posts with fields like media_file, position, longitude, latitude, etc.
Stores user tags on media files with x_coordinate, y_coordinate, post_media_id, user_id, etc.
Manages saved posts by users with post_id, user_id, created_date, etc.
Stores comments on posts with comment text, like_count, post_id, user_id, etc.
Manages the number of likes that a post or comment has.
Stores likes on posts and comments with fields like user_id, entity_id, entity_type, and created_date.
-
Users to User_details:
- Each user has only one set of user details (first name, last name, etc.), creating a one-to-one relationship
-
Users to Followers/Following (Follows Table):
- Many-to-many relationship where a user can follow multiple users and be followed by multiple users.
-
Users to Messages (Sender and Receiver):
- One-to-many relationship where a user can send multiple messages, but each message has one sender and one receiver.
-
Users to Posts:
- One-to-many relationship where a user can create multiple posts, but each post has one user as the creator.
-
Users to Saved_posts:
- One-to-many relationship where each user can have multiple saved posts (favorites or collections), but each saved post belongs to only one user.
-
Posts to Post Media:
- One-to-many relationship where a post can have multiple media files associated with it.
-
Posts to Post Media User Tags (Post_Media_User_Tag Table):
- Many-to-many relationship where multiple users can be tagged in multiple posts, and one post can have multiple users tagged in it.
-
Users to Comments:
- One-to-many relationship where a user can comment on multiple posts, but each comment has one user as the author.
-
Posts to Saved Posts (indirectly):
- Many-to-one. Each post can have multiple instances of being saved by different users, but each instance of saved post belongs to only one post. This relationship indirectly contributes to the many-to-many relationship between users and posts facilitated by the saved_posts junction table.
-
Posts to Comments
- One-to-many relationship where a post can have multiple comments, but each comment belongs to only one post.
-
Posts/Comments to Content Activity:
- One-to-one relationship where a post or a comment is associated with its like count.
-
Posts/Comments to Likes:
- One-to-many relationship where each post or comment can have multiple likes, but each like belongs to only one post or comment.