core: Track upgrade step within schema version
authorShane Synan <digitalcircuit36939@gmail.com>
Tue, 29 Jan 2019 04:08:03 +0000 (23:08 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 Feb 2019 19:41:19 +0000 (20:41 +0100)
commitf91f3faa1432894e6d6ecaaf0a1f60a483dd0129
tree8e610f0fa2342ada001aa6bbfa0f7ced59d2edb3
parent1e36d39ce542e12d94b388bea96cfcb76f40af23
core: Track upgrade step within schema version

Track the last successful upgrade step (upgrade_###_XXX.sql) within
each schema version, storing it within 'coreinfo' table as
'schemaupgradestep'. When a schema upgrade finishes, clear
'schemaupgradestep' and set 'schemaversion'.

This allows for resuming multi-step schema upgrades that were
interrupted in the middle.

Whenever starting a schema upgrade, also check the value of
'schemaupgradestep'.  One of two states exist:
1.  Empty ('') or nonexistent
    No interrupted schema upgrade, start the next schema version
    upgrade from the first query.
2.  Contains text, e.g. 'upgrade_010_alter_sender_64bit_ids'
    The schema upgrade was interrupted, skip schema upgrade steps
    including the specified successful step, and resume from the next
    step.

For case 2, if the schema upgrade step cannot be found, warn and bail
out.  This should only happen if:
1.  The storage of successful query glitched, or the database was
    manually changed
2.  Quassel changed the filenames of upgrade queries, and the local
    Quassel core version was replaced during an interrupted schema
    upgrade

Modify SqliteStorage and PostgreSqlStorage to fetch/save the
'schemaupgradestep' key.  Clearing this key is done atomically within
updateSchemaVersion().

(Ideally, the whole upgrade would be wrapped in a transaction, but
 that doesn't seem to be easily possible.)

Modify upgradeQueries() to return a list of query strings and
resource filenames, used for tracking the upgrade step and providing
clearer feedback on what steps fail.
src/core/abstractsqlstorage.cpp
src/core/abstractsqlstorage.h
src/core/postgresqlstorage.cpp
src/core/postgresqlstorage.h
src/core/sqlitestorage.cpp
src/core/sqlitestorage.h