Migrate the Procrastinate schema¶
When Procrastinate developers make changes to the Procrastinate database schema – the
schema.sql file in the code base – they need to write migration scripts.
Here’s an example of a migration script:
ALTER TABLE procrastinate_jobs ADD COLUMN extra TEXT;
The migration scripts are pure-SQL scripts, meaning that they may be applied to the
database using any PostgreSQL client, including
If you use Django, instead of using the SQL migration scripts directly, you way want to rely on the Procrastinate Django app, and the Django database migration scripts this app provides. See Use Procrastinate in a Django application for more information.
The migration scripts are located in the
procrastinate/sql/migrations directory of
the Procrastinate Git repository. They’re also shipped in the Python packages published
The names of migration script files adhere to a certain pattern:
xx.yy.zzis the version of Procrastinate the migration script can be applied to.
abis the migration script’s serial number,
01being the first number in the series.
Let’s say you are currently using Procrastinate 1.9.0, and you want to update to Procrastinate 1.15.0. In that case, before upgrading the Procrastinate Python package (from 1.9.0 to 1.15.0), you will need to apply all the migration scripts whose versions are greater than or equal to 1.9.0, and lower than 1.15.0 (1.9.0 ≤ version < 1.15.0). And you will apply them in version order, and, for a version, in serial number order. For example, you will apply the following migration scripts, in that order:
If you want to upgrade from one Procrastinate major version to another, say from Procrastinate 1.6.0 to 3.2.0, there are two options, depending on whether you can interrupt the service to do the migration or not.
The easier way, with service interruption¶
Shut down the services that use Procrastinate: both the services that defer tasks and the workers.
Apply all the migration scripts (1.6.0 ≤ version < 3.2.0).
Upgrade your code to the new Procrastinate version (3.2.0).
Start all the services.
This, as you’ve noticed, only works if you’re able to stop the services.
The safer way, without service interruption¶
This only applies starting at Procrastinate 0.17.0. For previous versions, you will have to interrupt the service or write custom migrations.
If you care about service continuity, you’ll need to make intermediate upgrades. For example, to upgrade from Procrastinate 1.6.0 to 3.2.0, here are the steps you will need to follow:
Apply all the migration scripts between 1.6.0 and 2.0.0 (1.6.0 ≤ version < 2.0.0).
Live-upgrade the Procrastinate version used in your services, from 1.6.0 to 2.0.0.
Apply all the migration scripts between 2.0.0 and 3.0.0 (2.0.0 ≤ version < 3.0.0).
Live-upgrade the Procrastinate version used in your services, from 2.0.0 to 3.0.0.
Apply all the migration scripts between 3.0.0 and 3.2.0 (3.0.0 ≤ version < 3.2.0).
Live-upgrade the Procrastinate version used in your services, from 3.0.0 and 3.2.0.
Following this process you can go from 1.6.0 to 3.2.0 with no service discontinuity.