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