Skip to content

Commit bcaef48

Browse files
committed
test: add database migrations check to CI
Signed-off-by: Mike Fiedler <[email protected]>
1 parent 411c021 commit bcaef48

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.github/workflows/ci.yml

+38
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,41 @@ jobs:
9393
key: ${{ runner.os }}-mypy-${{ env.pythonLocation }}-${{ hashFiles('requirements.txt', 'requirements/*.txt') }}
9494
- name: Run ${{ matrix.name }}
9595
run: ${{ matrix.command }}
96+
97+
check_db:
98+
name: Check Database Consistency
99+
needs: build
100+
runs-on: depot-ubuntu-22.04-arm
101+
continue-on-error: true
102+
container:
103+
image: registry.depot.dev/rltf7cln5v:${{ needs.build.outputs.buildId }}
104+
credentials:
105+
username: x-token
106+
password: ${{ needs.build.outputs.token }}
107+
services:
108+
postgres:
109+
image: postgres:16.1
110+
ports:
111+
- 5432:5432
112+
env:
113+
POSTGRES_DB: warehouse
114+
POSTGRES_HOST_AUTH_METHOD: trust # never do this in production!
115+
POSTGRES_INITDB_ARGS: '--no-sync --set fsync=off --set full_page_writes=off'
116+
# Set health checks to wait until postgres has started
117+
options: --health-cmd "pg_isready --username=postgres --dbname=postgres" --health-interval 10s --health-timeout 5s --health-retries 5
118+
steps:
119+
- name: Check out repository
120+
uses: actions/checkout@v4
121+
- name: Dotenv Action
122+
# We need to load the environment variables to run the CLI
123+
id: dotenv
124+
uses: falti/dotenv-action@v1
125+
with:
126+
path: dev/environment
127+
export-variables: true
128+
keys-case: upper
129+
- name: Check Database
130+
run: bin/db-check
131+
env:
132+
# override the hostname set in `dev/environment`
133+
DATABASE_URL: 'postgresql+psycopg://postgres@postgres/warehouse'

bin/db-check

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Check for outstanding database migrations
5+
python -m warehouse db upgrade head
6+
python -m warehouse db check

0 commit comments

Comments
 (0)