Skip to content

Commit

Permalink
Add ability to auto-generate alembic migrations
Browse files Browse the repository at this point in the history
We move to a slightly more general model where we can support specific
Alembic operations passed as arguments.

This was very useful to easily run the auto-generated migrations.
  • Loading branch information
portante committed Jan 30, 2023
1 parent ae866fa commit 56f055c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion jenkins/Pipeline.gy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pipeline {
stage('Server Alembic Migrations Check') {
steps {
echo 'Verify alembic migrations cover latest database schema'
sh 'jenkins/run-alembic-migrations-check'
sh 'jenkins/run-alembic-migrations check'
}
}
stage('Linting, Unit Tests, RPM builds') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ timeout 60s bash -c 'until nc -z localhost 5432; do
done'

echo "Starting tox" >&2
EXTRA_PODMAN_SWITCHES="${EXTRA_PODMAN_SWITCHES} --network host" jenkins/run tox -e alembic-check
EXTRA_PODMAN_SWITCHES="${EXTRA_PODMAN_SWITCHES} --network host" jenkins/run tox -e alembic-migration -- ${1:-check}
10 changes: 0 additions & 10 deletions lib/pbench/server/database/alembic.check

This file was deleted.

19 changes: 19 additions & 0 deletions lib/pbench/server/database/alembic.migration
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash -e

cd lib/pbench/server/database

# First we run all our migrations to bring the blank database up to speed.
alembic upgrade head

if [[ "${1}" == "check" ]]; then
# We have been asked to check to see if there are any model changes not
# captured in existing migrations.
alembic check
elif [[ "${1}" == "create" ]]; then
# We have been asked to auto-generate a migration based on the existing
# model compared against the most recent migration "head".
alembic revision --autogenerate
else
printf "Unsupported operation requested, '%s'\n" "${1}" >&2
exit 1
fi
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ deps =
-r{toxinidir}/agent/requirements.txt
-r{toxinidir}/agent/test-requirements.txt

[testenv:alembic-check]
[testenv:alembic-migration]
description = Verify alembic migrations cover latest database schema
deps =
-r{toxinidir}/server/requirements.txt
commands =
bash -c "{toxinidir}/lib/pbench/server/database/alembic.check"
bash -c "{toxinidir}/lib/pbench/server/database/alembic.migration {posargs}"

0 comments on commit 56f055c

Please sign in to comment.