From 040b91899e396ac2eb0910047c552aaa8e7b2181 Mon Sep 17 00:00:00 2001 From: Adam Ma Date: Wed, 31 Jan 2024 02:10:00 -0500 Subject: [PATCH 1/2] Leaderboards Table + Scores Table --- backend/go.mod | 2 +- backend/src/db/migrations/init.sql | 46 +++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/backend/go.mod b/backend/go.mod index 096ab295..6a75b7e5 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -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 ) @@ -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 diff --git a/backend/src/db/migrations/init.sql b/backend/src/db/migrations/init.sql index 5d2ffcb2..5c95b02d 100644 --- a/backend/src/db/migrations/init.sql +++ b/backend/src/db/migrations/init.sql @@ -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, @@ -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, + 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), +); + -- Insert sample data into "users" table INSERT INTO users (first_name, last_name, pass_word, email) VALUES ('Ania', 'Misiorek', 'password', 'email1@gmail.com'), - ('Leroy', 'Shaigorodsky', 'password', 'email2@gmail.com'); \ No newline at end of file + ('Leroy', 'Shaigorodsky', 'password', 'email2@gmail.com'), + ('Adam', 'Ma', 'password', 'email3@gmail.com'), + ('Madam', 'Ahh', 'password', 'email4@gmail.com'), + ('Adam', 'Ahh', 'password', 'email5@gmail.com'), + ('Madam', 'Ma', 'password', 'email6@gmail.com'); + +-- 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); \ No newline at end of file From 995461b090741669746ecb301b5db66832dfcdc2 Mon Sep 17 00:00:00 2001 From: Adam Ma Date: Thu, 1 Feb 2024 15:53:40 -0500 Subject: [PATCH 2/2] Requested Changes --- backend/src/db/migrations/init.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/db/migrations/init.sql b/backend/src/db/migrations/init.sql index 5c95b02d..9f6cdffe 100644 --- a/backend/src/db/migrations/init.sql +++ b/backend/src/db/migrations/init.sql @@ -11,19 +11,19 @@ CREATE TABLE IF NOT EXISTS users ( ); CREATE TABLE IF NOT EXISTS leaderboards ( - leaderboard_id INT AUTO_INCREMENT PRIMARY KEY, + leaderboard_id SERIAL PRIMARY KEY, leaderboard_name VARCHAR(255) NOT NULL, leaderboard_description TEXT ); CREATE TABLE IF NOT EXISTS scores ( - score_id INT AUTO_INCREMENT PRIMARY KEY, + score_id SERIAL 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), + FOREIGN KEY (leaderboard_id) REFERENCES leaderboards(leaderboard_id) ); -- Insert sample data into "users" table