Upgrading a Windows Server 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 Windows Server the upgrade is a backup, a code update, a dependency sync, the migrations and a restart:

  1. Stop the scheduled task and the web service

  2. Back up the database, and confirm the backup file is readable

  3. git fetch and git pull

  4. uv sync --exact --extra win --extra mssql, then activate .venv

  5. python manage.py check --database default

  6. python manage.py migrate and python manage.py collectstatic

  7. Start the service and scheduled task again

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.

Important

Of the three supported deployments - Ubuntu Linux, Windows Server and Docker - Windows is the one where this release changes the database most: it is the SQL Server deployment, and the unique constraints the 4.0 upgrade dropped are restored here. Read the SQL Server note below before you start.

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

Stop the scheduled task and the web service:

>>  Stop-ScheduledTask -TaskName "QATrack+ Django Q Cluster"
>>  Stop-Service "QATrack+ Web Service"

Back up the database with the service stopped, and check the backup before going further — see Backing up QATrack+. In SQL Server Management Studio, take a full backup and then run a RESTORE VERIFYONLY against the file it produced:

BACKUP DATABASE qatrackplus TO DISK = 'C:\backups\qatrackplus-pre-4.0.2.bak' WITH INIT;
RESTORE VERIFYONLY FROM DISK = 'C:\backups\qatrackplus-pre-4.0.2.bak';

Choose that folder by what SQL Server can write to, not by what you can. The file is written by the SQL Server service account rather than by you, so a folder you can save into may still be refused. The instance’s own default backup folder is always writable, and this prints it:

SELECT SERVERPROPERTY('InstanceDefaultBackupPath');

Then copy the file off the server. A backup beside the database it came from is one disk failure away from being no backup at all.

If SQL Server Management Studio is not installed

SSMS is a prerequisite for installing QATrack+, but it may never have been installed on a server somebody else set up, and it is not needed here. The same two statements run through sqlcmd, which comes with the SQL Server command line tools:

>>  sqlcmd -S .\SQLEXPRESS -E -C -Q "BACKUP DATABASE qatrackplus TO DISK = 'C:\backups\qatrackplus-pre-4.0.2.bak' WITH INIT;"
>>  sqlcmd -S .\SQLEXPRESS -E -C -Q "RESTORE VERIFYONLY FROM DISK = 'C:\backups\qatrackplus-pre-4.0.2.bak';"

-E signs in as your Windows account, and -C trusts the certificate the instance presents: current sqlcmd builds on ODBC Driver 18, which encrypts by default and refuses a local instance’s self-signed certificate without it, with “The certificate chain was issued by an authority that is not trusted”. Replace .\SQLEXPRESS with your own instance name.

Note

RESTORE VERIFYONLY proves the file is complete and readable. It does not prove the database restores from it. The only thing that proves that is a restore, and Proving a backup restores, and not only that it reads is the three-statement version that leaves your live database alone. Worth doing once, on a site whose backups have never been restored.

Back up the uploaded files too. They are not in the database, and a backup without them is not a complete set:

>>  Compress-Archive -Path C:\deploy\qatrackplus\qatrack\media -DestinationPath C:\backups\qatrackplus-media-pre-4.0.2.zip

python manage.py backup_site archives the same folder if you would rather use it - on every engine, including this one, even though it declines the database itself.

Fetch the new version and update the environment. You do not name a version — the releases/4.0 branch you installed from carries the patch:

>>  cd C:\deploy\qatrackplus
>>  git fetch origin
>>  git pull
>>  uv sync --exact --extra win --extra mssql

Activate the environment. uv sync updates .venv but does not activate it, and the commands below are run with the environment’s own python:

>>  .\.venv\Scripts\Activate.ps1

Your command prompt should now be prefixed with (qatrackplus) or (.venv). Without this, in a fresh PowerShell window python is the system interpreter - or Windows’ Python Store alias, which opens the Microsoft Store instead of running anything - so the commands below would either fail on missing dependencies or run against the wrong environment, while your services are stopped.

Check the installation. The --database is deliberate: the missing-constraint warnings have to ask SQL Server what it enforces, so they only appear when a connection is in play. Plain manage.py check reports no issues on a database that is missing all sixteen. The migrate that follows is what repairs them — the warnings are not asking you to act:

>>  python manage.py check --database default
>>  python manage.py check_unique_constraints

Then run the migrations and collect the static files:

>>  python manage.py migrate
>>  python manage.py collectstatic --noinput

Restart:

>>  Start-Service "QATrack+ Web Service"
>>  Start-ScheduledTask -TaskName "QATrack+ Django Q Cluster"

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.