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
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
@@ -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
@@ -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": {
@@ -61,7 +61,7 @@
"jdorn/sql-formatter": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"prefer-stable": false,
"autoload": {
"psr-4": {
"Atk4\\Data\\": "src/"
10 changes: 5 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion src/Persistence/GenericPlatform.php
Original file line number Diff line number Diff line change
@@ -14,7 +14,9 @@ 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';
5 changes: 5 additions & 0 deletions src/Persistence/Sql/Connection.php
Original file line number Diff line number Diff line change
@@ -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 .
7 changes: 5 additions & 2 deletions src/Persistence/Sql/DbalDriverMiddleware.php
Original file line number Diff line number Diff line change
@@ -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) {
44 changes: 33 additions & 11 deletions src/Persistence/Sql/Mssql/PlatformTrait.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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);
@@ -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) {
@@ -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
@@ -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, '.')) {
@@ -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, '.')) {
@@ -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, '.')) {
@@ -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,
@@ -154,7 +170,9 @@ public function getAddExtendedPropertySQL(
);
}

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

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getUpdateExtendedPropertySQL(
$name,
$value = null,
@@ -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, '.')) {
4 changes: 3 additions & 1 deletion src/Persistence/Sql/Oracle/PlatformTrait.php
Original file line number Diff line number Diff line change
@@ -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;
24 changes: 18 additions & 6 deletions src/Persistence/Sql/Postgresql/PlatformTrait.php
Original file line number Diff line number Diff line change
@@ -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();
@@ -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) {
@@ -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;
@@ -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(
4 changes: 3 additions & 1 deletion src/Persistence/Sql/Sqlite/PlatformTrait.php
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@

trait PlatformTrait
{
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getIdentifierQuoteCharacter(): string
{
return '`';
20 changes: 15 additions & 5 deletions src/Persistence/Sql/Sqlite/SchemaManagerTrait.php
Original file line number Diff line number Diff line change
@@ -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();
@@ -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);
@@ -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);
8 changes: 6 additions & 2 deletions src/Schema/TestSqlPersistence.php
Original file line number Diff line number Diff line change
@@ -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
@@ -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 {}
}
);
8 changes: 6 additions & 2 deletions src/Type/LocalObjectType.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
8 changes: 6 additions & 2 deletions src/Type/MoneyType.php
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@

class MoneyType extends DbalTypes\Type
{
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getName(): string
{
return Types::MONEY;
@@ -37,7 +39,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?float
return $this->convertToDatabaseValue($value, $platform);
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
3 changes: 1 addition & 2 deletions tests/ReferenceSqlTest.php
Original file line number Diff line number Diff line change
@@ -308,9 +308,8 @@ public function testReferenceWithObjectId(): void

$integerWrappedType = new class() extends DbalTypes\Type {
/**
* TODO: Remove once DBAL 3.x support is dropped.
* @deprecated remove once DBAL 3.x support is dropped
*/
#[\Override]
public function getName(): string
{
return self::class;