From 0a1f545c12f848e2a76188ca6df40f556d0f9c19 Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Fri, 20 Aug 2021 12:00:45 +0200 Subject: [PATCH] improve script --- CONTRIBUTING.md | 12 ++---------- new_migration.sh => scripts/new-migration.sh | 6 +++--- scripts/run-test.sh | 7 +++++++ 3 files changed, 12 insertions(+), 13 deletions(-) rename new_migration.sh => scripts/new-migration.sh (62%) create mode 100644 scripts/run-test.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ace9b5ce..ae1da4c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/new_migration.sh b/scripts/new-migration.sh similarity index 62% rename from new_migration.sh rename to scripts/new-migration.sh index 476a7d87..d2458117 100644 --- a/new_migration.sh +++ b/scripts/new-migration.sh @@ -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 \ No newline at end of file diff --git a/scripts/run-test.sh b/scripts/run-test.sh new file mode 100644 index 00000000..1941700e --- /dev/null +++ b/scripts/run-test.sh @@ -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 \ No newline at end of file