-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide the "Initial database schema" alembic migration #3174
Provide the "Initial database schema" alembic migration #3174
Conversation
FWIW, PR #3114 has a series of commits which change the database schema and I'd really like to engage Alembic migrations to help ensure our deployments work properly. More work needs to be done to integrate with Flask SQLAlchemy and Flask Migrate, but that can be done later. |
a7471fc
to
3684812
Compare
I saw comments on this PR via email, but I don't see them now. Weird. I'll record responses here ... The over-arching reason that I am using a These kinds of changes will be removed when we can start using Flask SQLAlchemy and Flask Migrate. In the mean time, these are part of the commit because they represent how I did this work. I used a Once we adopt Flask SQLAlchemy and Flask Migrate, all this can go away. I can also just remove these changes from the PR, but it seemed better to include and not encourage mystery. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any strict objection to the PR as long as we can document that these are intermittent changes subject to change again if and when we use Flask-Migrate
and Flask-SQLAlchemy
packages. As Dave said we also need to make sure that we have a mechanism to add this migration revision file inside the container (but I guess that can be a follow-up PR). On the Jira side, we also need a story to replace our current use of the python sqlalchemy
package with Flask Flask-SQLAlchemy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that (other than the comments below) this is all good...so I'll defer to Dave and Nikhil.
3684812
to
32930cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in exec-tests
which really should be fixed, and there's a typo in a commit in alembic.ini
; the rest are trivialities which you might as well consider since we need another cycle anyway.
Bugger all, it doesn't work. I think I have a solution for the failed CI job. Working on it ... |
Still working on a solution to the CI failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost have this working for the CI. Just need to see about a pg_isready
command for the CI environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit ugly, but at least the CI now has a way to verify a commit does not add a database schema change without providing a migration.
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. In order to make it convenient to work with migrations, we also create a `tox` environment, `alembic`, which simply invokes the new script `alembic.run` which one can modify to execute whatever Alembic commands are needed. The committed copy takes no actions, but has the initial commands used to create the first migration: alembic stamp head alembic revision --autogenerate -m "Initial tables" We also update the `alembic.ini` file to assume a `localhost` PostgreSQL database, and provide a Pbench Server configuration file that works in the Alembic environment.
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. We also remove the unused `alembic/alembic.ini`, drop the need for a separate `tox` environment, remove the need for a `pbench-server.cfg` file entirely by reverting to the original env.py as generated by `alembic init alembic`. We also collapse the existing migrations to one since we just need one to move from an empty database to our current schema.
We now run a very simple PostgreSQL container against which we run all our known migrations and then ask Alembic to check that we don't have any additional model changes which need a migration. The CI build will fail when any migrations are missing, and a local `tox -- server alembic` will also fail (really, any `tox` run that ends up running the server side, e.g. `tox -- server`, `tox -- all`, or just `tox`).
The build.sh is invoked inside a container, so we can't use podman from there to launch an empty live database. So move to a CI only pipeline check. One can run it locally by just invoking: jenkins/run-alembic-migrations-check
084849f
to
be04088
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff (although, I did find one nit which should be fixed).
However, I'm concerned that we don't have a coordinated source of truth for the PostgreSQL configuration stuff (version number, container image name, image tag, username, password, and database name): it's going to be too easy to forget that this test is out there when we decide to upgrade the canned server and the staging server to PG-15.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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, andalembic check
will fail if one is not provided.The existing
tox
environment will now run thealembic check
when the server side tests are executed. You can just run the check via:We update the
alembic.ini
file with the latest version generated by alembic 1.9.x, and it also assumes alocalhost
PostgreSQL database.The previous requirement of needing a
pbench-server.cfg
file has been removed by restoring thealembic/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 thealembic
subdirectory.