Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(db): provide database providers via IDB API #40423

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ protected function wasEmailTestSuccessful(): bool {

protected function hasValidTransactionIsolationLevel(): bool {
try {
if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
return true;
}

Expand Down Expand Up @@ -839,7 +839,7 @@ protected function hasBigIntConversionPendingColumns(): array {
];

$schema = new SchemaWrapper($this->db);
$isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform;
$isSqlite = $this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE;
$pendingColumns = [];

foreach ($tables as $tableName => $columns) {
Expand Down
19 changes: 19 additions & 0 deletions lib/private/DB/ConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Schema;
use OC\DB\Exceptions\DbalException;
use OCP\DB\IPreparedStatement;
Expand Down Expand Up @@ -242,4 +246,19 @@ public function migrateToSchema(Schema $toSchema): void {
public function getInner(): Connection {
return $this->inner;
}

public function getDatabaseProvider(): string {
Fixed Show fixed Hide fixed
$platform = $this->inner->getDatabasePlatform();
if ($platform instanceof MySQLPlatform) {
return IDBConnection::PLATFORM_MYSQL;
} elseif ($platform instanceof OraclePlatform) {
return IDBConnection::PLATFORM_ORACLE;
} elseif ($platform instanceof PostgreSQLPlatform) {
return IDBConnection::PLATFORM_POSTGRES;
} elseif ($platform instanceof SqlitePlatform) {
return IDBConnection::PLATFORM_SQLITE;
} else {
throw new \Exception('Database ' . $platform::class . ' not supported');
}
}
}
20 changes: 20 additions & 0 deletions lib/public/IDBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
* @since 6.0.0
*/
interface IDBConnection {
/* @since 28.0.0 */
public const PLATFORM_MYSQL = 'mysql';

/* @since 28.0.0 */
public const PLATFORM_ORACLE = 'oracle';

/* @since 28.0.0 */
public const PLATFORM_POSTGRES = 'postgres';

/* @since 28.0.0 */
public const PLATFORM_SQLITE = 'sqlite';

/**
* Gets the QueryBuilder for the connection.
*
Expand Down Expand Up @@ -339,4 +351,12 @@ public function createSchema(): Schema;
* @since 13.0.0
*/
public function migrateToSchema(Schema $toSchema): void;

/**
* Returns the database provider name
* @link https://github.com/nextcloud/server/issues/30877
miaulalala marked this conversation as resolved.
Show resolved Hide resolved
* @since 28.0.0
* @return IDBConnection::PLATFORM_*
*/
public function getDatabaseProvider(): string;
}