diff --git a/Database/CreateTables.ts b/Database/CreateTables.ts index 894aa72..cd7346a 100644 --- a/Database/CreateTables.ts +++ b/Database/CreateTables.ts @@ -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) ); @@ -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() { diff --git a/Database/FillDb.ts b/Database/FillDb.ts index bd181f9..8e65dbc 100644 --- a/Database/FillDb.ts +++ b/Database/FillDb.ts @@ -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)] ) diff --git a/package.json b/package.json index 066c2a0..71f5c30 100644 --- a/package.json +++ b/package.json @@ -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",