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

Upgrade DBAL to v4.0 #1111

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bootstrap-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

// force Doctrine\DBAL\Platforms\SQLitePlatform class load as in DBAL 3.x it is named with a different case
// remove once DBAL 3.x support is dropped
new SqlitePlatform();
try {
new SqlitePlatform();
} catch (\Error $e) {
}

DbalTypes\Type::addType(Types::LOCAL_OBJECT, LocalObjectType::class);
DbalTypes\Type::addType(Types::MONEY, MoneyType::class);
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"require": {
"php": ">=7.4 <8.4",
"atk4/core": "dev-develop",
"doctrine/dbal": "~3.5.1 || ~3.6.0",
"doctrine/dbal": "~3.5.1 || ~3.6.0 || ~4.0.0",
"mvorisek/atk4-hintable": "~1.9.0"
},
"require-release": {
"php": ">=7.4 <8.4",
"atk4/core": "~5.1.0",
"doctrine/dbal": "~3.5.1 || ~3.6.0",
"doctrine/dbal": "~3.5.1 || ~3.6.0 || ~4.0.0",
"mvorisek/atk4-hintable": "~1.9.0"
},
"require-dev": {
Expand All @@ -61,7 +61,7 @@
"jdorn/sql-formatter": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"prefer-stable": false,
"autoload": {
"psr-4": {
"Atk4\\Data\\": "src/"
Expand Down
10 changes: 5 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ parameters:
path: '*'
count: 3

# FC for DBAL 4.0, remove once DBAL 3.x support is dropped
-
message: '~^Class Doctrine\\DBAL\\Platforms\\SqlitePlatform referenced with incorrect case: Doctrine\\DBAL\\Platforms\\SQLitePlatform\.$~'
path: '*'
count: 25
# remove once DBAL 3.x support is dropped
-
message: '~^(Class Doctrine\\DBAL\\Platforms\\SQLitePlatform referenced with incorrect case: Doctrine\\DBAL\\Platforms\\SqlitePlatform\.|Dead catch - Error is never thrown in the try block\.)$~'
path: 'bootstrap-types.php'
count: 3

# TODO these rules are generated, this ignores should be fixed in the code
# for src/Schema/TestCase.php
Expand Down
4 changes: 3 additions & 1 deletion src/Persistence/GenericPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
use Doctrine\DBAL\Exception as DbalException;
use Doctrine\DBAL\Platforms;

class GenericPlatform extends Platforms\AbstractPlatform

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method createReservedKeywordsList() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method createSchemaManager() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getAlterTableSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getDateArithmeticIntervalExpression() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getDateDiffExpression() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getDateTimeTypeDeclarationSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getDateTypeDeclarationSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getListViewsSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getLocateExpression() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getSetTransactionIsolationSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method createReservedKeywordsList() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method createSchemaManager() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getAlterTableSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getDateArithmeticIntervalExpression() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getDateDiffExpression() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getDateTimeTypeDeclarationSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getDateTypeDeclarationSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getListViewsSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getLocateExpression() from class Doctrine\DBAL\Platforms\AbstractPlatform.

Check failure on line 10 in src/Persistence/GenericPlatform.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Non-abstract class Atk4\Data\Persistence\GenericPlatform contains abstract method getSetTransactionIsolationSQL() from class Doctrine\DBAL\Platforms\AbstractPlatform.
{
private function createNotSupportedException(): \Exception
{
return DbalException::notSupported('SQL');
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getName(): string
{
return 'atk4_data_generic';
Expand Down
5 changes: 5 additions & 0 deletions src/Persistence/Sql/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function getConnection(): DbalConnection
return $this->_connection;
}

final public static function isDbal3x(): bool
{
return (new \ReflectionClass(AbstractPlatform::class))->hasMethod('getName');
}

/**
* Normalize DSN connection string or DBAL connection params described in:
* https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html .
Expand Down
7 changes: 5 additions & 2 deletions src/Persistence/Sql/DbalDriverMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,19 @@ public function getDatabasePlatform(): AbstractPlatform
return $this->replaceDatabasePlatform(parent::getDatabasePlatform());
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function createDatabasePlatformForVersion($version): AbstractPlatform
{
return $this->replaceDatabasePlatform(parent::createDatabasePlatformForVersion($version));
}

/**
* @return AbstractSchemaManager<AbstractPlatform>
*
* @deprecated remove once DBAL 3.x support is dropped
*/
#[\Override]
public function getSchemaManager(DbalConnection $connection, AbstractPlatform $platform): AbstractSchemaManager
{
if ($platform instanceof SQLitePlatform) {
Expand Down
44 changes: 33 additions & 11 deletions src/Persistence/Sql/Mssql/PlatformTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

trait PlatformTrait
{
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getVarcharTypeDeclarationSQL(array $column)
{
$column['length'] = ($column['length'] ?? 255) * 4;
Expand All @@ -19,7 +21,9 @@ public function getVarcharTypeDeclarationSQL(array $column)

// remove once https://github.com/doctrine/dbal/pull/4987 is fixed
// and also $this->markDoctrineTypeCommented('text') below
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getClobTypeDeclarationSQL(array $column)
{
$res = parent::getClobTypeDeclarationSQL($column);
Expand All @@ -36,7 +40,9 @@ public function getClobTypeDeclarationSQL(array $column)
$this->markDoctrineTypeCommented('text');
} */

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getCurrentDatabaseExpression(bool $includeSchema = false): string
{
if ($includeSchema) {
Expand All @@ -46,7 +52,9 @@ public function getCurrentDatabaseExpression(bool $includeSchema = false): strin
return parent::getCurrentDatabaseExpression();
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getCreateIndexSQL(Index $index, $table)
{
// workaround https://github.com/doctrine/dbal/issues/5507
Expand All @@ -62,7 +70,9 @@ public function getCreateIndexSQL(Index $index, $table)
// SQL Server DBAL platform has buggy identifier escaping, fix until fixed officially, see:
// https://github.com/doctrine/dbal/pull/4360

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
protected function getCreateColumnCommentSQL($tableName, $columnName, $comment)
{
if (str_contains($tableName, '.')) {
Expand All @@ -83,7 +93,9 @@ protected function getCreateColumnCommentSQL($tableName, $columnName, $comment)
);
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
protected function getAlterColumnCommentSQL($tableName, $columnName, $comment)
{
if (str_contains($tableName, '.')) {
Expand All @@ -104,7 +116,9 @@ protected function getAlterColumnCommentSQL($tableName, $columnName, $comment)
);
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
protected function getDropColumnCommentSQL($tableName, $columnName)
{
if (str_contains($tableName, '.')) {
Expand All @@ -129,7 +143,9 @@ private function quoteSingleIdentifierAsStringLiteral(string $levelName): string
return $this->quoteStringLiteral(preg_replace('~^\[|\]$~', '', $levelName));
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getAddExtendedPropertySQL(
$name,
$value = null,
Expand All @@ -154,7 +170,9 @@ public function getAddExtendedPropertySQL(
);
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getDropExtendedPropertySQL(
$name,
$level0Type = null,
Expand All @@ -178,7 +196,9 @@ public function getDropExtendedPropertySQL(
);
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getUpdateExtendedPropertySQL(
$name,
$value = null,
Expand All @@ -203,7 +223,9 @@ public function getUpdateExtendedPropertySQL(
);
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
protected function getCommentOnTableSQL(string $tableName, ?string $comment): string
{
if (str_contains($tableName, '.')) {
Expand Down
4 changes: 3 additions & 1 deletion src/Persistence/Sql/Oracle/PlatformTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

trait PlatformTrait
{
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getVarcharTypeDeclarationSQL(array $column)
{
$column['length'] = ($column['length'] ?? 255) * 4;
Expand Down
24 changes: 18 additions & 6 deletions src/Persistence/Sql/Postgresql/PlatformTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@ private function getCreateCaseInsensitiveDomainsSql(): array
return $sqls;
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed ? 'ATK4__CICHAR' : 'ATK4__CIVARCHAR';
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getClobTypeDeclarationSQL(array $column)
{
return 'CITEXT';
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
protected function initializeDoctrineTypeMappings(): void
{
parent::initializeDoctrineTypeMappings();
Expand All @@ -55,7 +61,9 @@ protected function initializeDoctrineTypeMappings(): void
$this->doctrineTypeMapping['citext'] = 'text';
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getCurrentDatabaseExpression(bool $includeSchema = false): string
{
if ($includeSchema) {
Expand All @@ -65,7 +73,9 @@ public function getCurrentDatabaseExpression(bool $includeSchema = false): strin
return parent::getCurrentDatabaseExpression();
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function convertBooleansToDatabaseValue($item)
{
return $item;
Expand Down Expand Up @@ -139,7 +149,9 @@ protected function getCreateAutoincrementSql(Table $table, Column $pkColumn): ar
return $sqls;
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
$sqls = array_merge(
Expand Down
4 changes: 3 additions & 1 deletion src/Persistence/Sql/Sqlite/PlatformTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

trait PlatformTrait
{
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getIdentifierQuoteCharacter(): string
{
return '`';
Expand Down
20 changes: 15 additions & 5 deletions src/Persistence/Sql/Sqlite/SchemaManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

trait SchemaManagerTrait
{
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function alterTable(TableDiff $tableDiff): void
{
$hadForeignKeysEnabled = (bool) $this->_conn->executeQuery('PRAGMA foreign_keys')->fetchOne();
Expand All @@ -34,7 +36,9 @@ public function alterTable(TableDiff $tableDiff): void
// fix collations unescape for SqliteSchemaManager::parseColumnCollationFromSQL() method
// https://github.com/doctrine/dbal/issues/6129

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
protected function _getPortableTableColumnList($table, $database, $tableColumns)
{
$res = parent::_getPortableTableColumnList($table, $database, $tableColumns);
Expand All @@ -56,19 +60,25 @@ private function unquoteTableIdentifier(string $tableName): string
return (new Identifier($tableName))->getName();
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function listTableDetails($name): Table
{
return parent::listTableDetails($this->unquoteTableIdentifier($name));
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function listTableIndexes($table): array
{
return parent::listTableIndexes($this->unquoteTableIdentifier($table));
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function listTableForeignKeys($table, $database = null): array
{
return parent::listTableForeignKeys($this->unquoteTableIdentifier($table), $database);
Expand Down
8 changes: 6 additions & 2 deletions src/Schema/TestSqlPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public function getConnection(): Persistence\Sql\Connection
$this->getConnection()->getConnection()->getConfiguration()->setSQLLogger(
// @phpstan-ignore-next-line SQLLogger is deprecated
new class() implements SQLLogger {
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function startQuery($sql, array $params = null, array $types = null): void
{
// log transaction savepoint operations only once
Expand All @@ -52,7 +54,9 @@ public function startQuery($sql, array $params = null, array $types = null): voi
\Closure::bind(static fn () => $test->logQuery($sql, $params ?? [], $types ?? []), null, TestCase::class)(); // @phpstan-ignore-line
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function stopQuery(): void {}
}
);
Expand Down
8 changes: 6 additions & 2 deletions src/Type/LocalObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ protected function init(): void
$this->handlesIndex = [];
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getName(): string
{
return Types::LOCAL_OBJECT;
Expand Down Expand Up @@ -112,7 +114,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?object
return $res;
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
Expand Down
Loading
Loading