Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions Database/CreateTables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS games (
initial_price numeric(10,2),
discount_percent int,
image_url varchar(255),
genre varchar(255),
description text,
CONSTRAINT games_not_hidden CHECK (game_id <> 999999)
);
Expand Down Expand Up @@ -67,6 +68,9 @@ ALTER TABLE users
ADD COLUMN IF NOT EXISTS description text,
ADD COLUMN IF NOT EXISTS favourite_game int REFERENCES games (game_id) ON DELETE SET NULL,
ADD COLUMN IF NOT EXISTS setup varchar(255);
ALTER TABLE games
ADD COLUMN IF NOT EXISTS genre varchar(255);
`

async function createTables() {
Expand Down
6 changes: 4 additions & 2 deletions Database/FillDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@ async function FillDb() {

await pool.query(
`INSERT INTO games (game_id, game_name, current_price, initial_price,
discount_percent, image_url, description)
discount_percent, image_url, genre, description)
SELECT appid,
name,
CASE WHEN price = 'Free' THEN 0 ELSE price::numeric END,
initialprice::numeric,
discount::int,
img,
genre,
description
FROM jsonb_to_recordset($1::jsonb)
AS g(appid int, name text, price text, initialprice text,
discount text, img text, description text)
discount text, img text, genre text, description text)
ON CONFLICT (game_id) DO UPDATE SET
game_name = EXCLUDED.game_name,
current_price = EXCLUDED.current_price,
initial_price = EXCLUDED.initial_price,
discount_percent = EXCLUDED.discount_percent,
image_url = EXCLUDED.image_url,
genre = EXCLUDED.genre,
description = EXCLUDED.description`,
[JSON.stringify(chunk)]
)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"server": "node Backend/Server.ts",
"db:create": "node Database/CreateTables.ts",
"db:fill": "node Database/FillDb.ts",
"db:fill:genres":"node Database/FillGenres.ts",
"db:fill:genres": "node Database/FillGenres.ts",
"server:local": "node --env-file=Frontend/.env.development Backend/Server.ts",
"db:create:local": "node --env-file=Frontend/.env.development Database/CreateTables.ts",
"db:fill:local": "node --env-file=Frontend/.env.development Database/FillDb.ts",
"db:fill:genres:local":"node --env-file=Frontend/.env.development Database/FillGenres.ts"
"db:fill:genres:local": "node --env-file=Frontend/.env.development Database/FillGenres.ts"
},
"dependencies": {
"@apollo/server": "^5.5.1",
Expand Down