Upgrading a Docker 4.0.1 installation to 4.0.2

4.0.2 is a patch release that does run database migrations, unlike 4.0.1. On Docker you do not run them yourself - the django container applies them every time it starts - so the upgrade is a backup, a code update and a rebuild:

  1. Back up the database, and confirm the backup opens

  2. git fetch and git pull

  3. docker compose build

  4. docker compose up -d - this is the step that migrates

  5. Confirm, with manage.py check --database default inside the container

You never name a version. The installation guide checks out the releases/4.0 branch rather than a version tag, so the branch carries each patch as it is released and a git pull is all that moves you between them.

These steps apply to any 4.0.x patch, not only this one. What changes between patches is in the next section.

Before you start

Back up your database and your uploads, and check the backup opens. That is the same thing you would do before any QATrack+ upgrade.

If you have edited any files inside qatrack/, read Upgrading an installation you have modified at the end of this page before you pull: it asks you to record what you changed while that is still a one-line command.

Note

4.0.2 runs migrations, the way most QATrack+ releases have; 4.0.1 was the unusual one in having none. Nothing here deletes data: the migrations record field descriptions the models have declared for several releases, and restore unique constraints that SQL Server lost during the 4.0 upgrade.

Backing up QATrack+ says what a backup set has to contain, and - if your production database is SQLite - how to take one that is actually readable, which a file copy of a live database is not.

What you will see. migrate prints one line per migration. Upgrading 4.0.1 to 4.0.2 applies eight, one for most applications plus one that creates the cache table:

Applying attachments.0011_v4_0_2_final... OK
Applying faults.0016_v4_0_2_final... OK
Applying parts.0019_v4_0_2_final... OK
Applying qa.0061_v4_0_2_final... OK
Applying qatrack_core.0002_cache_table... OK
Applying reports.0011_v4_0_2_final... OK
Applying service_log.0029_v4_0_2_final... OK
Applying units.0022_v4_0_2_final... OK

migrate applies them in dependency order rather than the alphabetical order listed above - parts first, service_log last on most sites - so the eight lines appear in a different sequence to the one here. It also prints a handful of lines that are not migrations at all: “… next run updated to …” for each scheduled task it already had, and one “qatrack.reports.tasks.run_reports schedule created”. Those are django-q2 re-reading its schedule, not something the upgrade switched on.

Between them the eight carry 194 field alterations, two model-options changes and six data steps. The field alterations are the bulk of it and are the least interesting part: they bring the recorded schema into line with what the models have declared for several releases, so most make no change to your tables at all. The qa one is the largest at 132.

Three of those lines are worth recognising:

  • The SQL Server unique-constraint repair runs in four of them - parts.0019, qa.0061, service_log.0029 and units.0022. Each restores the unique indexes that engine lost for its own application’s tables, so on SQL Server these are the four lines that matter. qa.0061 is the slowest, carrying 132 of the 194 field alterations as well as its share of the repair. Of the remaining four, three are field state only; qatrack_core.0002_cache_table is the exception and is described next.

  • The cache table migration, qatrack_core.0002_cache_table, creates the cache table. Until 4.0.2 that table was created by manage.py createcachetable and by nothing else, so a database that had been migrated but never had that command run would fail at runtime. This migration removes that gap; if you have already run createcachetable, it finds the table and does nothing.

  • The permission rename, service_log.0029_v4_0_2_final, corrects one label. In 4.0.x both “can view service event” and “can review service event” were labelled Can review service event, so the admin’s permission list showed the same words twice for two different rights and there was no way to tell them apart when assigning them. The view permission now reads Can view service event.

    This is the one change in the upgrade an administrator will see. If you had already corrected the wording yourself, the migration leaves your version alone - it only replaces the exact 4.0.x text.

    Check your groups after upgrading if you assigned either permission by picking it from that list, because until now the two were indistinguishable there. review_serviceevent is the one that also allows changing a service event’s status.

If migrate applies more than these eight, the most likely reason is simply that the site was on 4.0.0 rather than 4.0.1, so it is catching up on 4.0.1’s migrations too - see the 4.0.0 upgrade guide for what those are. Worth a look either way, since it tells you where the database actually started.

Note

These eight are the whole 4.0.1 to 4.0.2 step. A fresh installation runs the full history instead - several hundred migrations, and several minutes - which is normal, and not what an upgrading site sees.

If you are on SQL Server, read this one

The 4.0 migrations silently dropped unique indexes on SQL Server - mssql-django drops them when an unrelated field change retypes a primary key, and never puts them back. Your database has been accepting duplicate rows that other backends would reject, including on TestListInstance.user_key, whose job is to keep API submissions unique.

4.0.2 restores them. You do not have to do anything, but two things are worth knowing:

  • migrate prints a warning for each missing constraint (qatrack.W014) before it applies anything, and then the same migrate repairs them. The warnings are not telling you to act.

    To see them without migrating, the command is python manage.py check --database default. Plain manage.py check will not show them: this check has to ask the database what it enforces, so it is registered to run only when a connection is in play, and check without --database reports “System check identified no issues” on a database that is missing all sixteen.

  • Rows that already violate a constraint block its repair. Run manage.py check_unique_constraints first to see whether you have any. A constraint that cannot be created is reported and skipped; the upgrade still finishes.

Dates and times will look different, and that is this release

Dates now display as YYYY-MM-DD by default, in every language, and the date pickers write back the same format they show.

This is the fix for a released bug: 4.0 wrote a date into a form in one format and read it back in another, so a pre-filled date was silently replaced with an unrelated one - usually months away and at midnight - before anyone had touched the page.

If your site needs its previous appearance, set QATRACK_DATE_FORMAT and QATRACK_DATETIME_FORMAT in local_settings.py. The release notes give the values that reproduce 4.0’s display.

Running the upgrade

Every command below starts in your QATrack+ checkout, written here as ~/web/qatrackplus. That is a placeholder for wherever you cloned it - the 4.0.1 guide did not say where to put it, and a 4.0.1 site may have it anywhere. docker compose has to run in deploy/docker inside that checkout, so if docker compose ps answers from where you are, you are in the right place.

Back up the database first and confirm the dump is readable. The deployment already has a backup service that does this nightly with pg_dump; run it once now, and check the dump it wrote — Backing up QATrack+ covers what a backup set must contain:

cd ~/web/qatrackplus/deploy/docker
docker compose exec backup bash /backup.sh
ls -t backups/db_*.dump | head -1

Then verify that dump in the same container, which has pg_restore available. Substitute the filename you just listed:

docker compose exec backup pg_restore --file=/dev/null /backups/db_YYYYMMDD_HHMMSS.dump \
    && echo "backup reads OK"

Upgrading from 4.0.0 or 4.0.1: keep your .env

From 4.0.2, deploy/docker/.env is no longer part of the QATrack+ repository, because it holds your database password. Your copy has your own settings in it, so on this one upgrade git pull stops with Your local changes to the following files would be overwritten. Before the first pull to 4.0.2 or later, set your .env aside and put it back afterwards:

cd ~/web/qatrackplus
cp deploy/docker/.env ../qatrack.env.backup
git checkout -- deploy/docker/.env
git stash push -m qatrack-4.0.2-upgrade
git branch --show-current
git checkout releases/4.0        # only if the line above printed something else
git pull
git stash list | grep -q qatrack-4.0.2-upgrade && git stash pop
cp ../qatrack.env.backup deploy/docker/.env

The branch check belongs here, in the middle of those commands, and not after them. An installation made before 4.0.2 was told to clone without naming a branch, so it sits on master - where git pull answers Already up to date and moves nothing, because master is still at the release before this one. The switch to releases/4.0 is what actually brings the new code, and it only works while your .env is set aside: with .env back in place it is a modified tracked file again, and git checkout releases/4.0 stops with Your local changes to the following files would be overwritten by checkout. A site already on releases/4.0 can leave the checkout line out; the git pull then does the work, as it does for every later patch.

git stash and git stash pop keep any other changes you have made to QATrack+’s files, such as a different port in deploy/docker/compose.yaml or edits to nginx.conf. 4.0.2 changes compose.yaml and the nginx files for the first time since 4.0.0, so without these steps git pull stops on any of them you have changed. If git stash replies No local changes to save, that’s fine: the grep line then skips git stash pop, so an older stash you may have is left alone. If it asks Please tell me who you are, tell git once, then run git stash again:

git config user.name "QATrack+ administrator"
git config user.email "you@example.com"

If you edited deploy/docker/nginx/conf.d/default.conf, for example to set up HTTPS, git stash pop reports a conflict on it and keeps your stash. 4.0.2 no longer uses that file: nginx is now configured from .env (see Serving QATrack+ over HTTPS). Save your old copy to compare with, then finish the step:

git show 'stash@{0}:deploy/docker/nginx/conf.d/default.conf' > ../old-nginx-default.conf
git rm -q deploy/docker/nginx/conf.d/default.conf
git reset -q
git status

Before you go on, check what git status lists. If any other file shows a conflict, most likely deploy/docker/compose.yaml, open it and resolve the section between the <<<<<<< and >>>>>>> markers by hand, keeping your change and 4.0.2’s. git stash show -p 'stash@{0}' shows every change you had stashed. Only once all of them are back in place, and no conflict markers are left, remove the stash - by its reference, not as a bare drop:

git stash drop 'stash@{0}'

Only run that if git stash pop reported a conflict. A pop that succeeded has already removed the stash, and a bare git stash drop would then delete whatever stash is now on top - which may be work of yours from weeks ago. If git stash list no longer shows qatrack-4.0.2-upgrade, there is nothing to drop and you can skip this.

Your other changes stay in place.

Your .env is now ignored by git, and later pulls leave it alone. Compare it with deploy/docker/.env.example, which lists every setting you can now make there: in particular set ALLOWED_HOSTS to the names people use to reach QATrack+. Keep qatrack.env.backup somewhere safe, or delete it: it holds your database password.

If your server is a Windows machine, see the note on line endings in the installation guide as well.

Confirm you are on the release branch

Installations made before 4.0.2 were told to git clone without naming a branch, which leaves the checkout on master rather than on a release. git pull then follows master, so the site can pick up work that has not been released, and a patch release never arrives at all. The switch above is what moves an existing installation onto the branch, once. Confirm it took:

cd ~/web/qatrackplus
git branch --show-current

releases/4.0 is the whole check. If it still prints master, the checkout line above was skipped or stopped on a modified file: read what git status lists, set aside anything of yours it names as the .env steps do, and run the checkout again.

Note

manage.py and the admin report the version from qatrack/settings.py, which is set by hand. A checkout of master therefore reports a release number too, so the branch name is the only thing that tells you which code you are running.

Then fetch the new version and rebuild:

cd ~/web/qatrackplus
git fetch origin
git pull
cd deploy/docker
docker compose build
docker compose up -d

up -d is where the database is upgraded. The django container’s entrypoint runs migrate before gunicorn on every start, and up -d does not return until django reports healthy, which it does only once the migrations and collectstatic have finished. The eight lines the previous section describes are therefore printed in the container’s log rather than in your terminal:

docker compose logs django

Then confirm the result. On Docker this is a check, not a step that does work - migrate reports No migrations to apply. because the container has already applied them, and that is the expected answer here rather than a sign the upgrade did not happen. check --database default is the one worth reading: it reports qatrack.W014 for any unique constraint still unenforced, as described above:

docker compose exec django python manage.py check --database default
docker compose exec django python manage.py migrate

Note

manage.py check reports configuration problems, not data problems — it will not tell you whether your backup contains a database. Checking that is step one above, not something the command can do for you.

Note

The django log prints a long notice about SECRET_KEY on its first 4.0.2 start, because 4.0.2 generates and keeps a key for you when .env does not set one. It is a notice rather than a problem, and a 4.0.1 site meets it here for the first time. Keeping the secret key safe says what the generated key is, why the nightly backup does not contain it, and how to copy it into your .env so that it does.

After upgrading

Check a date on a form. Open a form that has a pre-filled date and confirm it shows the date you expect. That is the fix this release exists for, and it is visible in ten seconds. The quickest two:

  • a new fault, at /faults/create/, whose Occurred field pre-fills with now;

  • an existing service event, at /servicelog/event/edit/<id>/, which shows a date that was stored before the upgrade rather than today’s.

Both should read YYYY-MM-DD, and the service event’s time should be the local time you recorded it at, not an offset from it.

On SQL Server, confirm the constraints came back:

python manage.py check --database default

should now report nothing. The --database is not optional here - plain manage.py check cannot see these warnings at all, and will say there are no issues whether or not every constraint is missing.

If it still reports qatrack.W014 for a table, that constraint was skipped because of duplicate rows. manage.py check_unique_constraints names them, and once they are resolved the repair can be run again by reversing the migration for that app and applying it forward:

python manage.py migrate parts 0018_v4_0_final
python manage.py migrate

Reversing removes the constraints that app’s migration added and applying it forward puts back every one it can - including the one that was skipped. A plain migrate on its own will not do it, because the migration is already recorded as applied.

Confirm your backups once more - if you act on one thing after this release, make it reading the output of your next backup run rather than its exit status.

Running the test suite against an installed server

You do not need to, and most sites never will. It is worth knowing how, because “the suite passes on my server” is the most direct answer to did this upgrade land cleanly, and two things stop it working on a deployment that was set up by following this guide.

The database user cannot create the test database. pytest reads your local_settings.py, so it talks to your real database server, and then asks it for a second, temporary database to run against. The user this guide creates owns the QATrack+ database and nothing else, so that request is refused:

# PostgreSQL
permission denied to create database
# SQL Server
CREATE DATABASE permission denied in database 'master'. (262)

Grant it for the run and take it away afterwards, rather than leaving it in place:

# PostgreSQL
sudo -u postgres psql -c "alter role qatrack createdb"
# ... run the suite ...
sudo -u postgres psql -c "alter role qatrack nocreatedb"
-- SQL Server
ALTER SERVER ROLE [dbcreator] ADD MEMBER [qatrack];
-- ... run the suite ...
ALTER SERVER ROLE [dbcreator] DROP MEMBER [qatrack];

The GUI tests need a browser. Around 35 of them drive a real one, and on a server with none installed they error at setup rather than being skipped. That is not a failure of your installation. Deselect them by marker - ignoring the file they mostly live in is not enough, because other test modules import its base class and define browser-driven tests of their own:

.venv/bin/python -m pytest -m "not selenium"

On Windows that is .venv\Scripts\python.exe -m pytest -m "not selenium", and the grant above is the SQL Server one.

Warning

Your own settings are in force while the suite runs, because pytest loads qatrack.settings and therefore your local_settings.py. A site with local modifications can see large numbers of failures that say nothing about QATrack+ - on the public demo server, a local restriction on calculated tests failed 140 of them, all for the same reason.

If that happens, put the differing settings in a module of their own and point the run at it, rather than editing the settings your site is serving with:

# qatrack/my_test_settings.py
from qatrack.settings import *  # noqa

SOME_LOCAL_RESTRICTION = False
.venv/bin/python -m pytest --ds=qatrack.my_test_settings

Upgrading an installation you have modified

If you have edited files inside qatrack/, check whether the upgrade touches the same ones before you pull. git status lists what you changed; keep a copy of the diff somewhere outside the checkout, because an upgrade that edits the same file will make you re-apply it by hand rather than merging it for you.

If you have already pulled, nothing is lost. git pull refuses to overwrite a file you have modified, so either it completed and your edits are still there, or it stopped and told you which files it would have overwritten. git status and git diff still answer the same question afterwards as before.

4.0.2 changes qatrack/qatrack_core/apps.py, which is a common place for sites to add start-up code of their own.