Skip to content

Commit

Permalink
feat: Database migration improvements and tests (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Sep 17, 2024
1 parent 896e3be commit e7f30f1
Show file tree
Hide file tree
Showing 13 changed files with 2,555 additions and 168 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 30

steps:
Expand All @@ -56,4 +56,13 @@ jobs:
- uses: bluefireteam/melos-action@v3
- run: melos run format-check
- run: melos run analyze -- ${{ inputs.fatal_warnings && '--fatal-infos' || '--no-fatal-warnings --no-fatal-infos' }}
- name: Prepare server
working-directory: wrestling_scoreboard_server
run: |
cp .env.example .env
source .env
sudo systemctl start postgresql.service
sudo -u postgres psql postgres -c "CREATE USER ${DATABASE_USER} WITH PASSWORD '${DATABASE_PASSWORD}';"
sudo -u postgres psql postgres -c "CREATE DATABASE ${DATABASE_NAME} WITH OWNER = ${DATABASE_USER};"
sudo -u postgres psql ${DATABASE_NAME} -c "ALTER SCHEMA public OWNER TO ${DATABASE_USER};"
- run: melos run test
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ Tags: scoreboard, wrestling, scoring, bracket, mat, team, fight, competition, to
The App consists of three components, the client, the server and the database.
You can download the client and the server for your preferred platforms from the [Releases section](https://github.com/Oberhauser-Dev/wrestling_scoreboard/releases).

For setting up the database and hosting a server, see:
- [Database](wrestling_scoreboard_server/database/README.md)
- [Server](wrestling_scoreboard_server/README.md#setup)
For setting up the database and hosting a server, see the [Server Setup](wrestling_scoreboard_server/README.md#setup).

## Development

Expand Down
4 changes: 2 additions & 2 deletions wrestling_scoreboard_server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ JWT_ISSUER='Wrestling Scoreboard (oberhauser.dev)'
JWT_SECRET=my-ultra-secure-and-ultra-long-secret
JWT_EXPIRES_IN_DAYS=90

DATABASE_HOST='localhost'
DATABASE_HOST='127.0.0.1'
DATABASE_PORT=5432
DATABASE_USER='wrestling'
DATABASE_PASSWORD=''
DATABASE_PASSWORD='my-password'
DATABASE_NAME='wrestling_scoreboard'

# One of: ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, SHOUT, OFF
Expand Down
17 changes: 10 additions & 7 deletions wrestling_scoreboard_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ Wrestling software server for managing team matches and competitions.

## Setup

See [database docs](./database/README.md), to set up the Postgres database.

It is recommended to start the app with user privileges, here `www`. Avoid using root.

Download the latest server version from the [releases section](https://github.com/Oberhauser-Dev/wrestling_scoreboard/releases)
and extract it into e.g. inside `$HOME/.local/share/wrestling_scoreboard_server`
and extract it into e.g. inside `$HOME/.local/share/wrestling_scoreboard_server`.

It is recommended to start the app with user privileges, here `www`. Avoid using `root`, especially if the server is open to the public.

### Environment variables:

Create file `.env` in the `wrestling_scoreboard_server` directory.
A pre-configuration can be found in `.env.example` file. Change the values to your needs.
A pre-configuration can be found in `.env.example` file (`cp .env.example .env`). Change the values to your needs.

### Database

For a manual / more detailed setup of the Postgres database, see the [database docs](./database/README.md).

### Run server

Expand Down Expand Up @@ -51,11 +53,12 @@ systemctl --user start wrestling-scoreboard-server.service
```

Additionally, enable session for user `www` on boot:

```bash
sudo loginctl enable-linger www
```

To view server logs:
To view server logs:
`journalctl --user -u wrestling-scoreboard-server`

### Web server
Expand Down
22 changes: 14 additions & 8 deletions wrestling_scoreboard_server/database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Then add this to your system PATH variable `C:/Program Files/PostgreSQL/<version
### Debian:

```shell
sudo apt-get install postgresql
sudo apt install postgresql
sudo apt install postgresql-client-common
sudo apt-get install postgresql-client
sudo apt install postgresql-client
```

## Setup
Expand All @@ -25,9 +25,10 @@ sudo apt-get install postgresql-client

Login as admin:
```shell
PGPASSWORD=mypassword
psql -U postgres
postgres=#
PGPASSWORD=my-password
psql -U postgres # For creation and dropping
psql -U postgres -d wrestling_scoreboard # For altering database wrestling_scoreboard
psql -U postgres -d wrestling_scoreboard -c "SELECT semver FROM migration LIMIT 1;" # Run command
```

On Linux you may want to log in as postgres user: `sudo -u postgres -i`
Expand All @@ -36,24 +37,29 @@ Use this on peer authentication:
```shell
sudo -u postgres psql postgres # For creation and dropping
sudo -u postgres psql wrestling_scoreboard # For altering database wrestling_scoreboard
sudo -u postgres psql wrestling_scoreboard -c "SELECT semver FROM migration LIMIT 1;" # Run command
```

### User

Create own user `wrestling`, replace `my_password` with the password of your choice:
Create own user `wrestling`, replace `my-password` with the password of your choice:
```shell
psql -U postgres -c "CREATE USER wrestling WITH PASSWORD 'my_password';"
psql -U postgres -c "CREATE USER wrestling WITH PASSWORD 'my-password';"
```

### Import / Restore prepopulated database & schema

You can `Export`, `Restore`, `Reset` or `Upgrade` your database from the server web page.
Or you execute these steps manually:

Reset current database:
Reset `wrestling_scoreboard` database from within the database `postgres`:
```shell
psql -U postgres -c "DROP DATABASE IF EXISTS wrestling_scoreboard;"
psql -U postgres -c "CREATE DATABASE wrestling_scoreboard WITH OWNER = wrestling;"
```

Assign `wrestling` as owner of `public` schema from within the database `wrestling_scoreboard`:
```shell
psql -U postgres -d wrestling_scoreboard -c "ALTER SCHEMA public OWNER TO wrestling;"
```

Expand Down
Loading

0 comments on commit e7f30f1

Please sign in to comment.