Skip to content

Commit

Permalink
[tests][postgres] Add migration test
Browse files Browse the repository at this point in the history
Starting from `sda-db` `v0.1.2` and running all migration scripts.
  • Loading branch information
jbygdell committed Sep 20, 2023
1 parent 0b8ea90 commit 06446b3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/integration/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ services:
volumes:
- ./scripts:/scripts

migration_helper:
container_name: helper
command:
- /usr/bin/tar
- -zxf
- /pgdata.tgz
- -C
- /pgdata/
image: ubuntu:jammy
user: 70:70
volumes:
- pgmigrate:/pgdata
- ./tests/postgres/pgdata.tgz:/pgdata.tgz

migrate:
container_name: migrate
depends_on:
migration_helper:
condition: service_completed_successfully
environment:
- POSTGRES_PASSWORD=rootpasswd
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 20s
retries: 3
image: ghcr.io/neicnordic/sensitive-data-archive:PR${PR_NUMBER}-postgres
ports:
- "35432:5432"
restart: always
volumes:
- pgmigrate:/var/lib/postgresql/data

postgres:
build:
context: ../../postgresql
Expand Down Expand Up @@ -80,6 +113,8 @@ services:
condition: service_completed_successfully
postgres:
condition: service_healthy
migrate:
condition: service_healthy
environment:
- PGPASSWORD=rootpasswd
image: ubuntu:jammy
Expand All @@ -88,9 +123,11 @@ services:
volumes:
- ./tests:/tests
- client_certs:/certs
- ../../postgresql/migratedb.d:/migratedb.d

volumes:
certs:
client_certs:
pgdata:
pgmigrate:
pgtlsdata:
8 changes: 8 additions & 0 deletions .github/integration/tests/postgres/10_sanity_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ for u in download finalize inbox ingest mapper sync verify; do
psql -U "$u" -h postgres -d sda -At -c "SELECT version();" 1>/dev/null
done

## verify that migrations worked
migratedb=$(find /migratedb.d/ -name "*.sql" -printf '%f\n' | sort -n | tail -1 | cut -d '.' -f1)
version=$(psql -U postgres -h migrate -d sda -At -c "select max(version) from sda.dbschema_version;")
if [ "$version" -ne "$migratedb" ]; then
echo "Migration scripts failed"
exit 1
fi

Binary file added .github/integration/tests/postgres/pgdata.tgz
Binary file not shown.

0 comments on commit 06446b3

Please sign in to comment.