Problem: currentlyThe MIGRATION_XXX constants do not allow for a migration process that has stages that write to the old and the new schema, but only reads from one of the schemas. For the MCR migration, it's more useful to first have a stage when both schemas are written but the old schema is still read, and then switching to a stage where both schemas are still written, but only the new schema is read: this allows us to exerciser the new code fore reading, while still avoiding extra fallback code (which is especially complex and error prone when we have to do it in a single SQL query), the foand still allowing us to easily back out of the migration modes are defined:and go back to using the old schema.
- MIGRATION_OLD: Only read and write the old schema.To achieve this, the migration stage should be defined as a bit field, The new schema need notwith individual bits that control reading and writing of the old and the new schema:
```
even exist.define( 'SCHEMA_COMPAT_WRITE_OLD', This is used from when the patch is merged until the schema0x01 );
change is actually applied to the database.define( 'SCHEMA_COMPAT_READ_OLD', 0x02 );
- MIGRATION_WRITE_BOTH: Write both the old and new schema.define( 'SCHEMA_COMPAT_WRITE_NEW', Read the new0x10 );
schema preferentially, falling back to the old.define( 'SCHEMA_COMPAT_READ_NEW', This is used while the0x20 );
change is being testeddefine( 'SCHEMA_COMPAT_WRITE_BOTH', allowing easy roll-back to the old schema.SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_WRITE_NEW );
- MIGRATION_WRITE_NEW: Write only the new schema.define( 'SCHEMA_COMPAT_READ_BOTH', Read the new schemaSCHEMA_COMPAT_READ_OLD | SCHEMA_COMPAT_READ_NEW );
preferentially, falling back to the old.define( 'SCHEMA_COMPAT_OLD', This is used while running theSCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_OLD );
maintenance script to migrate existing entries in the old schema to thedefine( 'SCHEMA_COMPAT_NEW', SCHEMA_COMPAT_WRITE_NEW | SCHEMA_COMPAT_READ_NEW );
new schema.
- MIGRATION_NEW: Only read and write the new schema. The old schema (and the
feature flag) may now be removed.
This requires code to be written that can read the new schema, but falls back to the old schema. This is simple enough in many cases, but for storage layer code that exposes a getQueryInfo mothod, like RevisionStore::getQueryInfo, this is quite difficult, since it requires conditional joins.```
In such casesTo keep the MIGRATION_XXX constants compatible with the new bit field logic, the code path with fallback executed MIGRATION_WRITE_BOTH and MIGRATION_WRITE_NEW is quite different from the post-migration code path later used by MIGRATION_NEWir numeric value is changed to contain the bit field in the lower bits, resulting in the post-migration code not being tested in MIGRATION_WRITE_BOTH and MIGRATION_WRITE_NEW modes.
Use case:
MCR schema migration without having to implement complex and inefficient fallback in RevisionStore::getQueryInfo.and use higher bits to preserve their original ordering, like so:
Proposal:
To solve this, a new MIGRATION_READ_NEW shojld be introduced, with the following semantics:
- MIGRATION_READ_NEW: Write both the old and new schema. Read only the new schema.
This is used to test operation based on the new schema, while still allowing easy roll-back to the
old schema.
Logically, this mode is an alternative to MIGRATION_WRITE_NEW. In natural order of the migration modes, it could be placed before or after MIGRATION_WRITE_NEW, but both placements have issues in the interpretation of the order: if MIGRATION_READ_NEW is placed before MIGRATION_WRITE_NEW, it disables reading from the old schema, but MIGRATION_WRITE_NEW enables it again. if placed after MIGRATION_WRITE_NEW, MIGRATION_READ_NEW re-enabled writing to the old schema after MIGRATION_WRITE_NEW disabled it.
A solution might be to re-define the semantic of all modes:
- MIGRATION_OLD: Only read and write the old schema. The new schema need not```
even exist. This is used from when the patch is merged until the schemalang=php
change is actually applied to the database.define( 'MIGRATION_OLD', 0x00000000 | SCHEMA_COMPAT_OLD );
- define( 'MIGRATION_WRITE_BOTH: Write both the old and new schema.', May try to read the0x10000000 | SCHEMA_COMPAT_READ_BOTH | SCHEMA_COMPAT_WRITE_BOTH );
new schema, but must fall back to the old.define( 'MIGRATION_WRITE_NEW', This is used while the0x20000000 | SCHEMA_COMPAT_READ_BOTH | SCHEMA_COMPAT_WRITE_NEW );
change is being tested, allowing easy roll-back to the old schema.define( 'MIGRATION_NEW', Maintenance script0x30000000 | SCHEMA_COMPAT_NEW );
to migrate existing entries in the old schema to the new schema may already be run.
- MIGRATION_WRITE_NEW: Write only the new schema. May try to read the
new schema, but must fall back to the old. This is used while running the
maintenance script to migrate existing entries in the old schema to the
new schema.
- MIGRATION_READ_NEW: Write both the old and new schema. Read only the new schema.
This is used to test operation based on the new schema, while still allowing easy roll-back to the
old schema.
- MIGRATION_NEW: Only read and write the new schema. The old schema (and the
feature flag) may now be removed.
Sensibly, migrations would be done either with read-fallback via the MIGRATION_WRITE_NEW stage, or without read-fallback with a MIGRATION_READ_NEW stage.
NOTE: all code that uses greater/smaller comparison on these constants should be changed to check for equality. Greater/smaller comparison can no longer be used safely.```