improve script

This commit is contained in:
Son Nguyen Kim 2021-08-20 12:00:45 +02:00
parent 009e1edced
commit 0a1f545c12
3 changed files with 12 additions and 13 deletions

View File

@ -42,16 +42,8 @@ brew install gnupg
## Run tests
Running test requires a Postgres database. You can run one with docker:
```bash
docker run -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test -p 15432:5432 postgres:13
```
then run all tests
```bash
pytest
sh scripts/run-test.sh
```
## Run the code locally
@ -93,7 +85,7 @@ Whenever the model changes, a new migration has to be created.
If you have Docker installed, you can create the migration by the following script:
```bash
sh new_migration.sh
sh scripts/new-migration.sh
```
Make sure to review the migration script before committing it.

View File

@ -1,16 +1,16 @@
# Generate a new migration script using Docker
# To run it:
# sh new_migration.sh
# sh scripts/new-migration.sh
# create a postgres database for SimpleLogin
docker rm -f sl-db
docker run -p 25432:5432 --name sl-db -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=sl -d postgres:13
# run run `flask db upgrade` to upgrade the DB to the latest stage and
env DB_URI=postgresql://postgres:postgres@127.0.0.1:25432/sl flask db upgrade
env DB_URI=postgresql://postgres:postgres@127.0.0.1:25432/sl poetry run flask db upgrade
# finally `flask db migrate` to generate the migration script.
env DB_URI=postgresql://postgres:postgres@127.0.0.1:25432/sl flask db migrate
env DB_URI=postgresql://postgres:postgres@127.0.0.1:25432/sl poetry run flask db migrate
# remove the db
docker rm -f sl-db

7
scripts/run-test.sh Normal file
View File

@ -0,0 +1,7 @@
# Run tests
docker run -d --name sl-test-db -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test -p 15432:5432 postgres:13
poetry run pytest
docker rm -f sl-test-db