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

Update README.md and backup dump #4

Merged
merged 1 commit into from
Oct 3, 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
63 changes: 28 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
# Welcome to Remix!
# Welcome to [Krokelo](https://krokelo.sb1u.no/)!

- [Remix Docs](https://remix.run/docs)
Krokelo is a web application created to track [Crocinole](https://en.wikipedia.org/wiki/Crokinole) games at SpareBank 1 Utvikling. You can submit duel games (1 vs 1) and team games (2 vs 2), and the application will calculate [Elo ratings](https://en.wikipedia.org/wiki/Elo_rating_system) for players and teams. Leaderboard and profile pages shows the current stats.

## Possible Todos

- [ ] Make it possible for players to be anonymous at stats and profile page.
- [ ] Match history for players
- [ ] Heat map for time of matches
The application is implemented in [Remix](https://remix.run/docs) with a [Postgres](https://en.wikipedia.org/wiki/PostgreSQL) database.

## Development

From your terminal:
### Spin up a Postgres dataabse

```sh
npm run dev
docker run --name postgres16 -e POSTGRES_DB=krokelo -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=666 -p 5432:5432 -d postgres:16
```

This starts your app in development mode, rebuilding assets on file changes.

## Local db setup

To run the app locally first you need a database to connect to.

### Spin up the postgres database image
### Create a .env file with required environment variables

`docker run --name postgres16 -e POSTGRES_DB=railway -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=666 -p 5432:5432 -d postgres:16`
```
DATABASE_URL="postgresql://postgres:666@localhost:5432/krokelo"
COOKIE_SECRET="s3cr3ts3cr3t"
```

### Add a .env file locally to define the DATABASE_URL
### Start app in development mode

`DATABASE_URL="postgresql://postgres:666@localhost:5432/railway"`
```sh
npm install # Install dependencies
npm run setup:db # Setup Prisma and migrate database
npm run dev # Start app in dev mode with hot reload
```

### Use prod data in local dev
### (Optional) Use prod data in local dev

There is a backup of the production data included in this project in the db_backups folder.
You can use this to get a more realistic dev env.
You can restore the backup data to your local db instance in pgadmin4 or via terminal:

```sh
docker cp db_backups/10feb2024.sql {container_id}:/10feb2024.sql
docker exec -i postgres16 pg_restore -U postgres -d railway 10feb2024.sql
docker cp db_backups/03oct2024.dump {container_id}:/03oct2024.dump
docker exec -i postgres16 pg_restore --clean --no-owner --no-privileges -U postgres -d krokelo 03oct2024.dump
```

### Run prisma migration

`npm run setup:db`

## Deployment

First, build your app for production:
Expand All @@ -59,13 +52,13 @@ Then run the app in production mode:
npm start
```

Now you'll need to pick a host to deploy it to.

### DIY

If you're familiar with deploying node applications, the built-in Remix app server is production-ready.
### Cheat sheet commands for database backup and restore

Make sure to deploy the output of `remix build`

- `build/`
- `public/build/`
```sh
# Backup database
pg_dump -Fc "postgresql://username:password@host:port/dbname" > db.dump
# Restore database (same owner and roles)
pg_restore --verbose -d dbname db.dump -h host -p port -U username
# Restore database (new owners and roles)
pg_restore --verbose --no-owner --role=username -d dbname db.dump -h host -p port -U username
```
Binary file added db_backups/03oct2024.dump
Binary file not shown.
Binary file removed db_backups/10feb2024.sql
Binary file not shown.
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import jsxa11y from 'eslint-plugin-jsx-a11y';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

export default [
{
ignores: ['public/*'],
},
{
files: ['app/**/*.{ts,tsx}'],
languageOptions: {
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
"build": "remix build",
"deploy:db": "prisma migrate deploy",
"dev": "remix dev --manual",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"generate:css": "tailwindcss -o ./app/styles/tailwind.css",
"prettier": "prettier . --check",
"lint": "eslint .",
"prettier:fix": "prettier . --write",
"prettier": "prettier . --check",
"setup:db": "prisma migrate dev",
"setup": "run-s setup:db setup:app",
"start": "remix-serve build/index.js",
"typecheck": "tsc --build tsconfig.json && :"
},
Expand Down
Loading