Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created "Following" Table and Sample Data in DB Schema #11

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion backend/src/db/migrations/init.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS following;
DROP TABLE IF EXISTS leaderboards;
DROP TABLE IF EXISTS scores;

Expand All @@ -10,6 +11,15 @@ CREATE TABLE IF NOT EXISTS users (
email VARCHAR NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS following (
following_id SERIAL PRIMARY KEY,
follower_user_id INT NOT NULL REFERENCES users(user_id),
following_user_id INT NOT NULL REFERENCES users(user_id),
follow_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT unique_following_pair UNIQUE (follower_user_id, following_user_id),
CONSTRAINT no_self_follow CHECK (follower_user_id != following_user_id)
);

CREATE TABLE IF NOT EXISTS leaderboards (
leaderboard_id SERIAL PRIMARY KEY,
leaderboard_name VARCHAR(255) NOT NULL,
Expand All @@ -25,7 +35,8 @@ CREATE TABLE IF NOT EXISTS scores (
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (leaderboard_id) REFERENCES leaderboards(leaderboard_id)
);



-- Insert sample data into "users" table
INSERT INTO users (first_name, last_name, pass_word, email)
VALUES
Expand All @@ -51,6 +62,16 @@ VALUES
('Sofia', 'Davis', 'r4nd0m', '[email protected]'),
('Adam', 'Ma', 'password', '[email protected]'),
('Madam', 'Ahh', 'password', '[email protected]'),


CREATE INDEX IF NOT EXISTS idx_follower_user_id ON following(follower_user_id);
CREATE INDEX IF NOT EXISTS idx_following_user_id ON following(following_user_id);

-- Insert sample data into "following" table
INSERT INTO following (follower_user_id, following_user_id)
VALUES
(1, 2),
(2, 1);

-- Insert sample data into "leaderboards" table
INSERT INTO leaderboards (leaderboard_name, leaderboard_description)
Expand Down
Loading