Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add makefile, docker-compose and migrate to node-postgres #422

Merged
merged 11 commits into from
Jun 13, 2024
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
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
DB_CONNECTION_URL=postgresql://postgres:secretpassword@localhost:5432
# DATABASE CONNECTION
DATABASE_HOST="localhost"
DATABASE_PORT="5432"
DATABASE_USER="postgres"
DATABASE_PASSWORD="secretpassword"
DATABASE_NAME="postgres"

PORT=8080
COOKIE_PASSWORD=YourPasswortMustBeAtLeast32Charc
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
# Provide the password for postgres
env:
POSTGRES_PASSWORD: secretpassword
POSTGRES_USER: postgres
POSTGRES_DB: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
Expand Down Expand Up @@ -50,3 +52,11 @@ jobs:

- name: Run unit tests
run: pnpm test
env:
DATABASE_PASSWORD: secretpassword
DATABASE_USER: postgres
DATABASE_NAME: postgres
DATABASE_HOST: localhost
DATABASE_PORT: 5432
PORT: 8080
COOKIE_PASSWORD: YourPasswortMustBeAtLeast32Charc
294 changes: 0 additions & 294 deletions DATABASE.md

This file was deleted.

17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Create DB container
docker-run:
@if docker compose up 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
docker-compose up; \
fi

# Shutdown DB container
docker-down:
@if docker compose down 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
docker-compose down; \
fi
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,33 @@

## For developers

1. install [nodejs v20](https://nodejs.org/en/download)
1. install [nodejs v20.14.0](https://nodejs.org/en/download)
- On WSL (Windows Subsystems for Linux) install `node.js v20` as follows:
```
1. curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
2. sudo apt install -y nodejs
```
2. install [pnpm](https://pnpm.io/installation#using-npm)
3. start a postgres `docker run --name postgres -e POSTGRES_PASSWORD=secretpassword -e POSTGRES_USER=postgres -p 5432:5432 -d postgres`
4. update .env with connection string `postgresql://postgres:secretpassword@localhost:5432` & cookie password.
5. pnpm i
6. pnpm dev
3. update .env with custom values
4. start services needed to run backend `make docker-run`
5. `pnpm install`
6. `pnpm build` only required on the first run
7. `pnpm dev`

### database list of commands

1. It is possible to visualize the database. Run: `pnpm db:studio`

2. It is possible to fill the database with random data. Run:
`pnpm db:seed`
### unit testing

3. It is possible to delete all entries from the database. Run:
`pnpm db:seed:cleanup`
- you can test you have set everything up correctly by running `pnpm test`

### unit testing
### database list of commands

- expects a database to be available at `postgresql://postgres:secretpassword@localhost:5432`
- It is possible to visualize the database. Run: `pnpm db:studio`
- It is possible to fill the database with random data. Run:
`pnpm db:seed`
- It is possible to delete all entries from the database. Run:
`pnpm db:seed:cleanup`

### db migrations

1. create a file in the [db](./src/db/) with the new table schema
2. run `pnpm generate`
2. run `pnpm db:generate`
3. restart server and migrations should auto run
Loading
Loading