Schema: Use virtual domain updater

That simplifies a lot of stuff

Bug: T314908
Change-Id: I2985c755a2302e7cc7c8ec55041f7e5d8192e4a7
This commit is contained in:
Amir Sarabadani 2023-12-21 23:44:25 +01:00 committed by Reedy
parent 57505f1976
commit 5c41b2a8e6

View file

@ -8,7 +8,7 @@ use FormatJson;
use MediaWiki\Extension\OATHAuth\Maintenance\UpdateForMultipleDevicesSupport; use MediaWiki\Extension\OATHAuth\Maintenance\UpdateForMultipleDevicesSupport;
use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook; use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IMaintainableDatabase; use Wikimedia\Rdbms\IDatabase;
class UpdateTables implements LoadExtensionSchemaUpdatesHook { class UpdateTables implements LoadExtensionSchemaUpdatesHook {
@ -20,9 +20,8 @@ class UpdateTables implements LoadExtensionSchemaUpdatesHook {
$baseDir = dirname( __DIR__, 2 ); $baseDir = dirname( __DIR__, 2 );
$typePath = "$baseDir/sql/$type"; $typePath = "$baseDir/sql/$type";
$updater->addExtensionTable( $updater->addExtensionUpdateOnVirtualDomain(
'oathauth_types', [ 'virtual-oathauth', 'addTable', 'oathauth_types', "$typePath/tables-generated.sql", true ]
"$typePath/tables-generated.sql"
); );
// If the old table exists, ensure it's up-to-date so the migration // If the old table exists, ensure it's up-to-date so the migration
@ -40,10 +39,13 @@ class UpdateTables implements LoadExtensionSchemaUpdatesHook {
case 'postgres': case 'postgres':
// 1.38 // 1.38
$updater->modifyExtensionTable( $updater->addExtensionUpdateOnVirtualDomain( [
'virtual-oathauth',
'modifyTable',
'oathauth_users', 'oathauth_users',
"$typePath/patch-oathauth_users-drop-oathauth_users_id_seq.sql" "$typePath/patch-oathauth_users-drop-oathauth_users_id_seq.sql",
); true
] );
break; break;
} }
@ -52,22 +54,16 @@ class UpdateTables implements LoadExtensionSchemaUpdatesHook {
UpdateForMultipleDevicesSupport::class, UpdateForMultipleDevicesSupport::class,
"$baseDir/maintenance/UpdateForMultipleDevicesSupport.php" "$baseDir/maintenance/UpdateForMultipleDevicesSupport.php"
] ); ] );
$updater->addExtensionUpdateOnVirtualDomain( [ 'virtual-oathauth', 'dropTable', 'oathauth_users' ] );
$updater->dropExtensionTable( 'oathauth_users' );
} }
// add new updates here // add new updates here
} }
/** private static function getDatabase(): IDatabase {
* @return IMaintainableDatabase return MediaWikiServices::getInstance()
*/
private static function getDatabase() {
$db = MediaWikiServices::getInstance()
->getDBLoadBalancerFactory() ->getDBLoadBalancerFactory()
->getPrimaryDatabase( 'virtual-oathauth' ); ->getPrimaryDatabase( 'virtual-oathauth' );
'@phan-var IMaintainableDatabase $db';
return $db;
} }
/** /**
@ -90,11 +86,6 @@ class UpdateTables implements LoadExtensionSchemaUpdatesHook {
*/ */
public static function switchTOTPScratchTokensToArray() { public static function switchTOTPScratchTokensToArray() {
$db = self::getDatabase(); $db = self::getDatabase();
if ( !$db->fieldExists( 'oathauth_users', 'data' ) ) {
return true;
}
$res = $db->newSelectQueryBuilder() $res = $db->newSelectQueryBuilder()
->select( [ 'id', 'data' ] ) ->select( [ 'id', 'data' ] )
->from( 'oathauth_users' ) ->from( 'oathauth_users' )