2 namespace MediaWiki\Tests\Revision
;
4 use Wikimedia\Rdbms\IDatabase
;
7 * Trait providing methods for detecting which MCR schema migration phase the current schema
10 trait McrSchemaDetection
{
13 * Returns true if MCR-related tables exist in the database.
14 * If yes, the database is compatible with with MIGRATION_NEW.
15 * If hasPreMcrFields() also returns true, the database supports MIGRATION_WRITE_BOTH mode.
17 * @param IDatabase $db
20 protected function hasMcrTables( IDatabase
$db ) {
21 return $db->tableExists( 'slots', __METHOD__
);
25 * Returns true if pre-MCR fields still exist in the database.
26 * If yes, the database is compatible with with MIGRATION_OLD mode.
27 * If hasMcrTables() also returns true, the database supports MIGRATION_WRITE_BOTH mode.
29 * Note that if the database has been updated in MIGRATION_NEW mode,
30 * the rev_text_id field will be 0 for new revisions. This means that
31 * in MIGRATION_OLD mode, reading such revisions will fail, even though
32 * all the necessary fields exist.
33 * This is not relevant for unit tests, since unit tests reset the database content anyway.
35 * @param IDatabase $db
38 protected function hasPreMcrFields( IDatabase
$db ) {
39 return $db->fieldExists( 'revision', 'rev_content_model', __METHOD__
);