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

Leaderboards Table + Scores Table #10

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/spf13/viper v1.18.2
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.2
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)
Expand Down Expand Up @@ -63,7 +64,6 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/swaggo/swag v1.16.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/urfave/cli/v2 v2.27.1 // indirect
Expand Down
46 changes: 45 additions & 1 deletion backend/src/db/migrations/init.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS leaderboards;
DROP TABLE IF EXISTS scores;

CREATE TABLE IF NOT EXISTS users (
user_id SERIAL PRIMARY KEY,
Expand All @@ -8,8 +10,50 @@ CREATE TABLE IF NOT EXISTS users (
email VARCHAR NOT NULL
);

CREATE TABLE IF NOT EXISTS leaderboards (
leaderboard_id INT AUTO_INCREMENT PRIMARY KEY,
leoRysing marked this conversation as resolved.
Show resolved Hide resolved
leaderboard_name VARCHAR(255) NOT NULL,
leaderboard_description TEXT
);

CREATE TABLE IF NOT EXISTS scores (
score_id INT AUTO_INCREMENT PRIMARY KEY,
score INT NOT NULL,
score_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
user_id INT NOT NULL,
leaderboard_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (leaderboard_id) REFERENCES leaderboards(leaderboard_id),
leoRysing marked this conversation as resolved.
Show resolved Hide resolved
);

-- Insert sample data into "users" table
INSERT INTO users (first_name, last_name, pass_word, email)
VALUES
('Ania', 'Misiorek', 'password', '[email protected]'),
('Leroy', 'Shaigorodsky', 'password', '[email protected]');
('Leroy', 'Shaigorodsky', 'password', '[email protected]'),
('Adam', 'Ma', 'password', '[email protected]'),
('Madam', 'Ahh', 'password', '[email protected]'),
('Adam', 'Ahh', 'password', '[email protected]'),
('Madam', 'Ma', 'password', '[email protected]');

-- Insert sample data into "leaderboards" table
INSERT INTO leaderboards (leaderboard_name, leaderboard_description)
VALUES
('Penny Stocks', 'Leaderboard for traders with the most successful penny stock trades.'),
('Blue Chip Stocks', 'Leaderboard for traders with the most successful blue chip stock trades.');

-- Insert sample data into "scores" table
INSERT INTO scores (score, user_id, leaderboard_id)
VALUES
(100, 1, 1),
(200, 2, 1),
(150, 3, 1),
(250, 4, 1),
(300, 5, 1),
(400, 6, 1),
(20, 1, 2),
(10, 2, 2),
(30, 3, 2),
(40, 4, 2),
(50, 5, 2),
(60, 6, 2);
Loading