- Python application for storing table tennis results
- Docker
- Python version 3.8
Copy the contents from tt-stats-backend/backend/backend/.env.dist
to tt-stats-backend/backend/backend/.env
Run docker-compose up
and go to localhost:8000/graphql
Write query to test that the GraphQL interface is working
query {
hello
}
or fetch players
query {
players {
id,
name
matchWinner {id}
matchLoser {id}
}
}
Write mutation to create a match:
mutation {
createMatch(loserId: 1, winnerId: 2) {
match {
id
winner {
id
name
}
loser {
id
name
}
createdAt
updatedAt
}
}
}
Copy contents from tt-stats-frontend/.env.dist
to tt-stats-frontend/.env.local
cd tt-stats-frontend
yarn serve
and open localhost:8080
cd tt-stats-frontend
yarn gql:generate
Commands for formatting and type checking:
cd tt-stats-frontend
yarn lint
yarn lint --fix
yarn types:chck
Generate migrations with command
docker-compose exec tt-stats-backend bash -c "python backend/manage.py makemigrations src"
Run all migrations with command
docker-compose exec tt-stats-backend bash -c "python backend/manage.py migrate"
docker-compose exec tt-stats-db bash
psql -U tt-stats
\c tt-stats
docker-compose exec tt-stats-backend bash -c "pip install package_name"
docker-compose exec tt-stats-backend bash -c "pip freeze > requirements.txt"
As you develop, the backend application should work normally. NOTE: Every time you run a new version of the backend where new packages is installed you are required to build the Docker image again:
docker-compose up --build tt-stats-backend
Insert two players into database with command
cat ./database-seeds/insert-players.sql| docker-compose exec -T tt-stats-db psql -U tt-stats
or use django to create player with a random name
docker-compose exec tt-stats-backend bash -c "python backend/manage.py create-random-players --amount 10"
amount is required argument
Use django to create matches with random outcomes with:
docker-compose exec tt-stats-backend bash -c "python backend/manage.py create-random-matches --amount 10"
amount is required argument
Delete all matches with command
docker-compose exec tt-stats-backend bash -c "python backend/manage.py delete-all-matches"
and all players with command
docker-compose exec tt-stats-backend bash -c "python backend/manage.py delete-all-players"