Merge pull request #945 from simple-login/run-migration-in-ci

Run migration in ci
This commit is contained in:
Son Nguyen Kim 2022-05-02 10:20:12 +02:00 committed by GitHub
commit 65bc6c7fdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -77,6 +77,10 @@ jobs:
poetry run black --check . poetry run black --check .
poetry run flake8 poetry run flake8
- name: Run db migration
run: |
CONFIG=tests/test.env poetry run alembic upgrade head
- name: Test with pytest - name: Test with pytest
run: | run: |
poetry run pytest poetry run pytest

View File

@ -1,12 +1,19 @@
# Run tests # Run tests
# Delete the test DB if it isn't properly removed
docker rm -f sl-test-db 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 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 sleep 3
# migrate the DB to the latest version
CONFIG=tests/test.env poetry run alembic upgrade head
# run test
poetry run pytest poetry run pytest
# Delete the test DB
docker rm -f sl-test-db docker rm -f sl-test-db

View File

@ -9,7 +9,6 @@ os.environ["CONFIG"] = os.path.abspath(
import sqlalchemy import sqlalchemy
from app.db import Session, engine, connection from app.db import Session, engine, connection
from app.models import Base
from psycopg2 import errors from psycopg2 import errors
from psycopg2.errorcodes import DEPENDENT_OBJECTS_STILL_EXIST 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") print(">>> pg_trgm can't be dropped, ignore")
conn.execute("Rollback") conn.execute("Rollback")
Base.metadata.create_all(engine)
add_sl_domains() add_sl_domains()