Skip to content

Commit da2a567

Browse files
committed
feat(db): add method to test mariadb
There are some behavioral differences that apps may need to check for. See discussion on #51175 for more info. This preserves the existing behavior of getDatabaseProvider() Signed-off-by: Varun Patil <varunpatil@ucla.edu>
1 parent 894463b commit da2a567

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

lib/private/DB/Connection.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1717
use Doctrine\DBAL\Exception;
1818
use Doctrine\DBAL\Exception\ConnectionLost;
19+
use Doctrine\DBAL\Platforms\MariaDBPlatform;
1920
use Doctrine\DBAL\Platforms\MySQLPlatform;
2021
use Doctrine\DBAL\Platforms\OraclePlatform;
2122
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
@@ -915,11 +916,13 @@ private function getConnectionName(): string {
915916
}
916917

917918
/**
918-
* @return IDBConnection::PLATFORM_MYSQL|IDBConnection::PLATFORM_ORACLE|IDBConnection::PLATFORM_POSTGRES|IDBConnection::PLATFORM_SQLITE
919+
* @return IDBConnection::PLATFORM_MYSQL|IDBConnection::PLATFORM_ORACLE|IDBConnection::PLATFORM_POSTGRES|IDBConnection::PLATFORM_SQLITE|IDBConnection::PLATFORM_MARIADB
919920
*/
920-
public function getDatabaseProvider(): string {
921+
public function getDatabaseProvider(bool $strict = false): string {
921922
$platform = $this->getDatabasePlatform();
922-
if ($platform instanceof MySQLPlatform) {
923+
if ($strict && $platform instanceof MariaDBPlatform) {
924+
return IDBConnection::PLATFORM_MARIADB;
925+
} elseif ($platform instanceof MySQLPlatform) {
923926
return IDBConnection::PLATFORM_MYSQL;
924927
} elseif ($platform instanceof OraclePlatform) {
925928
return IDBConnection::PLATFORM_ORACLE;

lib/private/DB/ConnectionAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ public function getInner(): Connection {
237237
}
238238

239239
/**
240-
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE
240+
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE|self::PLATFORM_MARIADB
241241
*/
242-
public function getDatabaseProvider(): string {
243-
return $this->inner->getDatabaseProvider();
242+
public function getDatabaseProvider(bool $strict = false): string {
243+
return $this->inner->getDatabaseProvider($strict);
244244
}
245245

246246
/**

lib/public/IDBConnection.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ interface IDBConnection {
4444
*/
4545
public const PLATFORM_SQLITE = 'sqlite';
4646

47+
/**
48+
* @since 32.0.0
49+
*/
50+
public const PLATFORM_MARIADB = 'mariadb';
51+
4752
/**
4853
* Gets the QueryBuilder for the connection.
4954
*
@@ -357,11 +362,13 @@ public function migrateToSchema(Schema $toSchema): void;
357362

358363
/**
359364
* Returns the database provider name
365+
*
366+
* @param bool $strict differentiate between database flavors, e.g. MySQL vs MariaDB
360367
* @link https://github.com/nextcloud/server/issues/30877
361368
* @since 28.0.0
362-
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE
369+
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE|self::PLATFORM_MARIADB
363370
*/
364-
public function getDatabaseProvider(): string;
371+
public function getDatabaseProvider(bool $strict = false): string;
365372

366373
/**
367374
* Get the shard definition by name, if configured

0 commit comments

Comments
 (0)