wiki.techinc.nl/tests/phpunit/includes/Storage/McrSchemaDetection.php
daniel 32e9266d8d Introduce per-schema unit tests for revision storage.
This introduces traits for testing different schema variations.
These are not very useful in this patch, but make it much easier
to add tests for MCR schema migration in subsequent patches.

The code in this patch was previously part of If259b1e1c49ceaa4.

Change-Id: I239572f75bebbc9c731a3e3860c4eff179dc15e4
2018-06-07 13:31:16 +00:00

42 lines
1.3 KiB
PHP

<?php
namespace MediaWiki\Tests\Storage;
use Wikimedia\Rdbms\IDatabase;
/**
* Trait providing methods for detecting which MCR schema migration phase the current schema
* is compatible with.
*/
trait McrSchemaDetection {
/**
* Returns true if MCR-related tables exist in the database.
* If yes, the database is compatible with with MIGRATION_NEW.
* If hasPreMcrFields() also returns true, the database supports MIGRATION_WRITE_BOTH mode.
*
* @param IDatabase $db
* @return bool
*/
protected function hasMcrTables( IDatabase $db ) {
return $db->tableExists( 'slots', __METHOD__ );
}
/**
* Returns true if pre-MCR fields still exist in the database.
* If yes, the database is compatible with with MIGRATION_OLD mode.
* If hasMcrTables() also returns true, the database supports MIGRATION_WRITE_BOTH mode.
*
* Note that if the database has been updated in MIGRATION_NEW mode,
* the rev_text_id field will be 0 for new revisions. This means that
* in MIGRATION_OLD mode, reading such revisions will fail, even though
* all the necessary fields exist.
* This is not relevant for unit tests, since unit tests reset the database content anyway.
*
* @param IDatabase $db
* @return bool
*/
protected function hasPreMcrFields( IDatabase $db ) {
return $db->fieldExists( 'revision', 'rev_content_model', __METHOD__ );
}
}