-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide the "Initial database schema" alembic migration (#3174)
Since we already have been using the database for quite some time, we create an initial migration which will take an empty database to the database base schema version as of commit 6a764f1. That commit was the most recent version deployed in Red Hat's staging environment. The existing revision migration was removed so that we only have a migration from empty database to fully populated. Starting with Alembic v1.9.0, the command, `alembic check`, is available which will succeed if no migrations are required, and fail if it detects that a migration is necessary. So future PRs will have to provide a migration revision if a change to the database schema is made in the PR, where `alembic check` will fail if one is not provided. A new `tox` environment, `alembic-check`, will now run the `alembic check`. Invoked via: tox -e alembic-check The actual check is provided by the script: jenkins/run-alembic-migrations-check That script runs a very simple PostgreSQL container against on the `localhost` (which is why `alembic.ini` is configured to reference a `localhost` database). It then runs all our known migrations (`alembic upgrade head`) and then ask Alembic to check that we don't have any additional model changes which need a migration (`alembic check`). The CI build will fail when any migrations are missing, and a local `tox -e alembic-check` will also fail. We have updated the `alembic.ini` file with the latest version generated by alembic 1.9.x. The previous requirement of needing a `pbench-server.cfg` file has been removed by restoring the `alembic/env.py` file back to the default with a small change to reference our database metadata. We have removed the unneeded `alembic.ini` file in the `alembic` sub- directory.
- Loading branch information
Showing
11 changed files
with
283 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash -e | ||
|
||
podman run --name postgresql-alembic \ | ||
--detach \ | ||
--rm \ | ||
--network host \ | ||
--workdir /opt/app-root/src \ | ||
--env 'PATH=/opt/app-root/src/bin:/opt/app-root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' \ | ||
--env 'TERM=xterm' \ | ||
--env 'container=oci' \ | ||
--env 'STI_SCRIPTS_URL=image:///usr/libexec/s2i' \ | ||
--env 'PGUSER=postgres' \ | ||
--env 'PLATFORM=el8' \ | ||
--env 'APP_DATA=/opt/app-root' \ | ||
--env 'CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/postgresql' \ | ||
--env 'ENABLED_COLLECTIONS' \ | ||
--env 'POSTGRESQL_VERSION=13' \ | ||
--env 'APP_ROOT=/opt/app-root' \ | ||
--env 'STI_SCRIPTS_PATH=/usr/libexec/s2i' \ | ||
--env 'HOME=/var/lib/pgsql' \ | ||
--env 'POSTGRESQL_USER=pbench' \ | ||
--env 'POSTGRESQL_PASSWORD=pbench' \ | ||
--env 'POSTGRESQL_DATABASE=pbench' \ | ||
images.paas.redhat.com/pbench/postgresql-13:latest container-entrypoint run-postgresql | ||
|
||
trap "podman stop postgresql-alembic" INT ABRT QUIT EXIT | ||
|
||
until nc -z localhost 5432; do | ||
sleep 1 | ||
done | ||
|
||
EXTRA_PODMAN_SWITCHES="${EXTRA_PODMAN_SWITCHES} --network host" jenkins/run tox -e alembic-check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/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 | ||
|
||
# Then we check to see if we have any model changes not captured in existing | ||
# migrations. | ||
alembic check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.