csc302-spring-2021 / proj-DaTeam

CSC302 course project for DaTeam
https://dateam-frontend.herokuapp.com/
5 stars 2 forks source link

feat: added DatabaseManager that connects to DB #99

Closed otomn closed 3 years ago

otomn commented 3 years ago

Description

Checklist

QA Steps

Production docker compose setting

  1. Go to the root directory
  2. Copy the .env.template to .env
  3. Run the following commands
    npm run clean:ci
    npm install
    npm run docker:build
    npm run docker:up
  4. Verify the following log is printed:
    backend-local | 
    backend-local | > @dateam/backend@1.0.0 start
    backend-local | > node ./build/Server.js
    backend-local | 
    backend-local | {
    backend-local |   host: 'postgres',
    backend-local |   port: 5432,
    backend-local |   database: 'dateam',
    backend-local |   user: 'dateam',
    backend-local |   password: 'dateam'
    backend-local | }
    backend-local | 18:56:33 connect(dateam@dateam); useCount: 0
    backend-local | 18:56:33 disconnect(dateam@dateam)
    backend-local | 18:56:33 connect(dateam@dateam); useCount: 0
    backend-local | 18:56:33 select count(*) from item
    backend-local | 18:56:34 disconnect(dateam@dateam)
    backend-local | { count: '0' }

Local development setting

  1. In .env, set DB_HOST=localhost
  2. Go to backend folder
  3. Run the following commands
    rm -rf dbdata
    docker rm pgdb # may fail, but doesn't matter
    docker create --name pgdb \
    -e POSTGRES_USER=dateam \
    -e POSTGRES_PASSWORD=dateam \
    -e PGDATA=/var/lib/postgresql/data/pgdata \
    -v "$(PWD)/dbdata":/var/lib/postgresql/data \
    -v "$(PWD)/src/db/DBInitSQL":/docker-entrypoint-initdb.d \
    -p 5432:5432 \
    postgres:alpine
    docker start pgdb
    docker logs --follow pgdb
  4. Wait until you see database system is ready to accept connections
  5. Run node build/Server.js
  6. Verify the following log is printed
    node build/Server.js
    development
    {
    host: 'localhost',
    port: 5432,
    database: 'dateam',
    user: 'dateam',
    password: 'dateam'
    }
    14:09:46 connect(dateam@dateam); useCount: 0
    14:09:46 select count(*) from item
    14:09:46 connect(dateam@dateam); useCount: 0
    14:09:46 disconnect(dateam@dateam)
    14:09:46 disconnect(dateam@dateam)
    { count: '0' }
otomn commented 3 years ago

@umar-ahmed Auto test is failing due to database not setup. Any solution?

umar-ahmed commented 3 years ago

@umar-ahmed Auto test is failing due to database not setup. Any solution?

Not sure why frontend build is failing, maybe try resetting package-lock.json and running npm install from root again.

In terms of the backend tests, there are two options:

DiademShoukralla commented 3 years ago

QA:

Production Docker Compose settings

Verify the log output: image

❓ Missing some expected output

backend-local | 18:56:33 connect(dateam@dateam); useCount: 0
backend-local | 18:56:33 select count(*) from item
backend-local | 18:56:34 disconnect(dateam@dateam)
backend-local | { count: '0' }

Also frontend-local did not start up. Not sure if the discrepancies are related

Local Development settings

image ❓ Same as above.. missing some expected output

@otomn For the most part, seems good, however some expected output is missing in both cases (the last 4 lines)

otomn commented 3 years ago

In the previous commit, I deleted the test query. I have added it back because we need it to see if the database schema is setup properly or not.

otomn commented 3 years ago

Test instruction

.env.template is updated, update the local .env before running the test The rest of the steps are the same

Expected output for docker test:

backend-local | 
backend-local | > @dateam/backend@1.0.0 start
backend-local | > node ./build/Server.js
backend-local | 
backend-local | {
backend-local |   host: 'postgres',
backend-local |   port: 5432,
backend-local |   database: 'dateam',
backend-local |   user: 'dateam',
backend-local |   password: 'dateam'
backend-local | }
backend-local | 21:22:42 connect(dateam@dateam); useCount: 0
backend-local | 21:22:42 SELECT count(*) FROM item
backend-local | 21:22:42 disconnect(dateam@dateam)
backend-local | Dabase is setup

Expected output for local test:

node build/Server.js
{
  host: 'localhost',
  port: 5432,
  database: 'dateam',
  user: 'dateam',
  password: 'dateam'
}
16:24:01 connect(dateam@dateam); useCount: 0
16:24:01 SELECT count(*) FROM item
16:24:01 disconnect(dateam@dateam)
Dabase is setup
otomn commented 3 years ago

@PersonalCorrect please test again

DiademShoukralla commented 3 years ago

QA

Docker/Production Test

image ✔️ QA Pass

Local Test

image ❌ QA Fail: Error executing one of the queries Log: image

DiademShoukralla commented 3 years ago

Hmm, I still keep getting the same error when doing the local test. I followed all steps listed (ensuring dbdata folder is deleted). The production/docker test still passes; this is only an issue with the local test.

Some things I noticed (which might help debugging?):