From 9558113e1a7c4ef4086b975d51b40c70b96153f2 Mon Sep 17 00:00:00 2001 From: Swe-yy Date: Mon, 18 May 2026 18:24:35 +0200 Subject: [PATCH 1/3] added pgadmin setup to view tables. Had to update the schema to work with postgres --- backend/Dockerfile | 2 +- database/init.sql | 44 ++++++++++++++++++++------------------------ docker-compose.yml | 34 ++++++++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 762ff88..4e65258 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -9,4 +9,4 @@ COPY . . EXPOSE 3000 -CMD ["node", "src/server.js"] \ No newline at end of file +CMD ["node", "src/server.ts"] \ No newline at end of file diff --git a/database/init.sql b/database/init.sql index bf62d7e..3c0a62d 100644 --- a/database/init.sql +++ b/database/init.sql @@ -1,4 +1,9 @@ --very generic tables that can be changed later, just trying not to keep the file empty + +CREATE TYPE problem_category AS ENUM ('math', 'programming'); +CREATE TYPE difficulty_level AS ENUM('Easy','Medium','Difficult'); +CREATE TYPE supported_languages AS ENUM('java','c++'); + CREATE TABLE IF NOT EXISTS users ( user_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), username VARCHAR(50) UNIQUE NOT NULL, @@ -7,8 +12,17 @@ CREATE TABLE IF NOT EXISTS users ( created_at TIMESTAMP DEFAULT NOW() ); +CREATE TABLE IF NOT EXISTS problems ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + type problem_category NOT NULL, + difficulty_level difficulty_level NOT NULL, + title VARCHAR(20) NOT NULL, + description VARCHAR(40) NOT NULL, + time_limit TIME(2) NOT NULL +); + CREATE TABLE IF NOT EXISTS match_problems( - match_problems_id PRIMARY KEY DEFAULT gen_random_uuid(), + match_problems_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), question1 UUID REFERENCES problems(id) NOT NULL, question2 UUID REFERENCES problems(id) NOT NULL, question3 UUID REFERENCES problems(id) NOT NULL, --every match has a minimum of 3 questions, i.e. difficult mode @@ -36,44 +50,26 @@ CREATE TABLE IF NOT EXISTS match_log( elo_lost INTEGER ); -CREATE TYPE problem_category AS ENUM ('math', 'programming'); - -CREATE TABLE IF NOT EXISTS problems ( - id SERIAL PRIMARY KEY, - type problem_category NOT NULL, - difficulty_level ENUM('Easy', 'Medium', 'Difficult') NOT NULL, - title VARCHAR(20) NOT NULL, - description VARCHAR(40) NOT NULL, - time_limit TIME(2) NOT NULL -); - CREATE TABLE IF NOT EXISTS elo_ratings ( elo_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID REFERENCES users(user_id), rating INTEGER DEFAULT 600, - updated_at TIMESTAMP DEFAULT NOW(), - + updated_at TIMESTAMP DEFAULT NOW() ); CREATE TABLE IF NOT EXISTS math_problems ( id SERIAL PRIMARY KEY, - problem_id INT NOT NULL REFERENCES problems(id) ON DELETE CASCADE, + problem_id UUID NOT NULL REFERENCES problems(id) ON DELETE CASCADE, --equation VARCHAR(20) NOT NULL, - solution_formula VARCHAR(20) NOT NULL, - CONSTRAINT math_category_check CHECK ( - (SELECT type FROM problems WHERE id = problem_id) = 'math' - ) + solution_formula VARCHAR(20) NOT NULL ); CREATE TABLE IF NOT EXISTS programming_problems ( id SERIAL PRIMARY KEY, - problem_id INT NOT NULL REFERENCES problems(id) ON DELETE CASCADE, + problem_id UUID NOT NULL REFERENCES problems(id) ON DELETE CASCADE, --function_signature VARCHAR(25) NOT NULL, - supported_languages ENUM('java', 'c++') NOT NULL, - CONSTRAINT programming_category_check CHECK ( - (SELECT type FROM problems WHERE id = problem_id) = 'programming' - ) + supported_languages supported_languages NOT NULL ); CREATE TABLE IF NOT EXISTS elo_history ( diff --git a/docker-compose.yml b/docker-compose.yml index 23219cf..f298807 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: backend: build: ./backend @@ -12,6 +10,8 @@ services: volumes: - ./backend:/app - /app/node_modules + networks: + - pgnetwork # frontend: # build: ./frontend @@ -24,16 +24,34 @@ services: db: image: postgres:15-alpine + container_name: postgres environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: password - POSTGRES_DB: codeclash + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASS} + POSTGRES_DB: ${POSTGRES_DB} ports: - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data - ./database/init.sql:/docker-entrypoint-initdb.d/init.sql + networks: + - pgnetwork + pgadmin: + image: dpage/pgadmin4:9.15 + container_name: pgadmin + environment: + PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL} + PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASS} + PGADMIN_LISTEN_PORT: ${PGADMIN_PORT} + ports: + - "${PGADMIN_PORT}:5151" + volumes: + - pgadmin_data:/var/lib/pgadmin + depends_on: + - db + networks: + - pgnetwork # judge0: # image: judge0/judge0:latest # ports: @@ -42,4 +60,8 @@ services: #TODO IMPORTANT return this when we want to start implementing code execution volumes: - postgres_data: \ No newline at end of file + postgres_data: + pgadmin_data: + +networks: + pgnetwork: \ No newline at end of file From 7fd8db545f87e73b68a857525ee82595284a5c46 Mon Sep 17 00:00:00 2001 From: Swe-yy Date: Mon, 18 May 2026 18:32:23 +0200 Subject: [PATCH 2/3] updated readme with pgadmin instructions --- backend/README.md | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/backend/README.md b/backend/README.md index c2b2cc6..1363c0c 100644 --- a/backend/README.md +++ b/backend/README.md @@ -105,6 +105,31 @@ To run tests with coverage: npm test -- --coverage ``` + +##PG-Admin + +1. make sure the docker is running +2. open: + ``` + http://localhost:5151 + ``` +3. login using pgadmin email and password and +4. right click on 'Servers" +5. navigate to Register > Server +6. in the 'General' tab + ``` + Name: postgres + ``` +7. in the 'Connection' tab + ``` + Host: db + Maintenance database: postgres db (from env) + Username: postgres user (from env) + Password: postgres password (from env) + ``` +8. 'Save' + + ## Project Structure ``` @@ -130,14 +155,14 @@ All API endpoints are prefixed with `/api`. A full list of service contracts is ## Tech Stack -| Concern | Technology | -|---|---| -| Runtime | Node.js v18 | -| Framework | Express | -| Database | PostgreSQL 15 | -| Code Execution | Judge0 | -| Testing | Jest | -| Containerisation | Docker | +| Concern | Technology | +| ---------------- | ------------- | +| Runtime | Node.js v18 | +| Framework | Express | +| Database | PostgreSQL 15 | +| Code Execution | Judge0 | +| Testing | Jest | +| Containerisation | Docker | ## Common Issues From 4cf404f51249278a2d426df21d64bb601757f24b Mon Sep 17 00:00:00 2001 From: Swe-yy Date: Mon, 18 May 2026 18:34:05 +0200 Subject: [PATCH 3/3] fixed small mistakes in readme --- backend/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/README.md b/backend/README.md index 1363c0c..2ed145b 100644 --- a/backend/README.md +++ b/backend/README.md @@ -105,15 +105,14 @@ To run tests with coverage: npm test -- --coverage ``` - -##PG-Admin +## PG-Admin 1. make sure the docker is running 2. open: ``` http://localhost:5151 ``` -3. login using pgadmin email and password and +3. login using pgadmin email and password 4. right click on 'Servers" 5. navigate to Register > Server 6. in the 'General' tab