diff --git a/.github/workflows/test-db-backup.yaml b/.github/workflows/test-db-backup.yaml index 67b84130..4cbde745 100644 --- a/.github/workflows/test-db-backup.yaml +++ b/.github/workflows/test-db-backup.yaml @@ -36,6 +36,16 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.10 + + - name: Install python deps + run: | + python -m pip install pytest sqlmodel psycopg2-binary + python -m pip install . --no-deps + - name: Install PostgreSQL client run: | sudo apt-get update @@ -50,11 +60,9 @@ jobs: env: PGPASSWORD: postgres_password - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: 3.10 - - - name: Install python deps + - name: Test restored database + if: always() run: | - python -m pip install pytest + pytest -vvxs db-backup/test_db_backup.py + env: + DATABASE_URL: postgresql://postgres_user:postgres_password@localhost:5432/postgres_db diff --git a/db-backup/test_db_backup.py b/db-backup/test_db_backup.py index e69de29b..3309728a 100644 --- a/db-backup/test_db_backup.py +++ b/db-backup/test_db_backup.py @@ -0,0 +1,15 @@ +import os + +from sqlmodel import Session, create_engine, select + +from pangeo_forge_orchestrator.models import MODELS + + +def test_db_backup(): + database_url = os.environ["DATABASE_URL"] + connect_args = dict(options="-c timezone=utc") + engine = create_engine(database_url, echo=False, connect_args=connect_args) + with Session(engine) as session: + statement = select(MODELS["feedstock"].table) + fstocks = session.exec(statement).all() + print(fstocks)