From c748ab22e6a42d44a3e03d02e49313f84cf7329e Mon Sep 17 00:00:00 2001 From: Son Date: Sun, 1 May 2022 17:06:10 +0200 Subject: [PATCH 1/3] run db migration in github ci --- .github/workflows/main.yml | 4 ++++ tests/conftest.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 54186f8a..4471dad8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,6 +77,10 @@ jobs: poetry run black --check . poetry run flake8 + - name: Run db migration + run: | + poetry run alembic upgrade head + - name: Test with pytest run: | poetry run pytest diff --git a/tests/conftest.py b/tests/conftest.py index 3a0d4abe..1647c8e5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,7 +34,7 @@ with engine.connect() as conn: print(">>> pg_trgm can't be dropped, ignore") conn.execute("Rollback") -Base.metadata.create_all(engine) +# Base.metadata.create_all(engine) add_sl_domains() From e74362dd9f90055d3219b094a65920e035a8ab88 Mon Sep 17 00:00:00 2001 From: Son Date: Sun, 1 May 2022 17:22:05 +0200 Subject: [PATCH 2/3] set config --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4471dad8..d1348b6b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -79,7 +79,7 @@ jobs: - name: Run db migration run: | - poetry run alembic upgrade head + CONFIG=tests/test.env poetry run alembic upgrade head - name: Test with pytest run: | From 2de5161cd297bca82a115cb2a6abf447d326e7c9 Mon Sep 17 00:00:00 2001 From: Son Date: Sun, 1 May 2022 17:38:14 +0200 Subject: [PATCH 3/3] run alembic in run-test.sh --- scripts/run-test.sh | 9 ++++++++- tests/conftest.py | 3 --- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/run-test.sh b/scripts/run-test.sh index 2411221d..37599204 100644 --- a/scripts/run-test.sh +++ b/scripts/run-test.sh @@ -1,12 +1,19 @@ # Run tests +# Delete the test DB if it isn't properly removed docker rm -f sl-test-db +# Create a test DB docker run -d --name sl-test-db -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test -p 15432:5432 postgres:13 -# the time the DB container starts +# the time for the test DB container to start sleep 3 +# migrate the DB to the latest version +CONFIG=tests/test.env poetry run alembic upgrade head + +# run test poetry run pytest +# Delete the test DB docker rm -f sl-test-db diff --git a/tests/conftest.py b/tests/conftest.py index 1647c8e5..a8c5ce69 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ os.environ["CONFIG"] = os.path.abspath( import sqlalchemy from app.db import Session, engine, connection -from app.models import Base from psycopg2 import errors from psycopg2.errorcodes import DEPENDENT_OBJECTS_STILL_EXIST @@ -34,8 +33,6 @@ with engine.connect() as conn: print(">>> pg_trgm can't be dropped, ignore") conn.execute("Rollback") -# Base.metadata.create_all(engine) - add_sl_domains()