From c80a62bdfd84489cbe8e2054f79762b7eb27db5f Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sun, 14 Apr 2024 18:23:08 +0200 Subject: [PATCH 1/3] feat: support doctrine/dbal 4 --- composer.json | 2 +- src/Services/DatabaseToolCollection.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d47e5e9e..2b39a754 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ }, "conflict": { "doctrine/annotations": "<1.13.1 || >=3.0", - "doctrine/dbal": "<2.13.1 || ~3.0.0 || >=4.0", + "doctrine/dbal": "<2.13.1 || ~3.0.0 || >=5.0", "doctrine/mongodb-odm": "<2.2 || >=3.0", "doctrine/orm": "<2.14 || >=4.0" }, diff --git a/src/Services/DatabaseToolCollection.php b/src/Services/DatabaseToolCollection.php index 31cfb64a..fea1d322 100644 --- a/src/Services/DatabaseToolCollection.php +++ b/src/Services/DatabaseToolCollection.php @@ -40,7 +40,9 @@ public function __construct(ContainerInterface $container, mixed $annotationRead public function add(AbstractDatabaseTool $databaseTool): void { - $this->items[$databaseTool->getType()][$databaseTool->getDriverName()] = $databaseTool; + $driverName = self::normalizeDriverName($databaseTool->getDriverName()); + + $this->items[$databaseTool->getType()][$driverName] = $databaseTool; } public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode = null): AbstractDatabaseTool @@ -49,6 +51,8 @@ public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode $registry = $this->container->get($registryName); $driverName = ('ORM' === $registry->getName()) ? \get_class($registry->getConnection()->getDatabasePlatform()) : 'default'; + $driverName = self::normalizeDriverName($driverName); + $databaseTool = $this->items[$registry->getName()][$driverName] ?? $this->items[$registry->getName()]['default']; $databaseTool->setRegistry($registry); @@ -57,4 +61,17 @@ public function get($omName = null, $registryName = 'doctrine', ?int $purgeMode return $databaseTool; } + + /** + * On doctrine/dbal ^4.0, the class is named `SQLitePlatform`. + * On doctrine/dbal < 4.0, the class is named `SqlitePlatform`. + */ + private static function normalizeDriverName(string $driverName): string + { + if ('Doctrine\DBAL\Platforms\SqlitePlatform' === $driverName) { + return 'Doctrine\DBAL\Platforms\SQLitePlatform'; + } + + return $driverName; + } } From bf29b7d7c50280f6f96a38dd8eede57ec7529355 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sat, 4 May 2024 15:16:22 +0200 Subject: [PATCH 2/3] chore: update versions of databases used on GitHub Actions: use MariaDB 11 and PostgreSQL 15 --- .github/workflows/tests.yml | 10 +++++----- docker-compose.yml | 2 +- tests/AppConfigMysql/config.yml | 1 + tests/AppConfigMysqlUrl/config.yml | 2 +- tests/AppConfigPgsql/config.yml | 1 + 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index da28f066..c8cfbcb2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,15 +27,15 @@ jobs: symfony-version: "^7.0" services: - mysql: - image: mysql:5.7 + mariadb: + image: mariadb:11.0 env: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: acme + MARIADB_ROOT_PASSWORD: root + MARIADB_DATABASE: acme ports: - 3306:3306 postgresql: - image: postgres:9.6 + image: postgres:15-alpine env: POSTGRES_USER: 'postgres' POSTGRES_PASSWORD: 'postgres' diff --git a/docker-compose.yml b/docker-compose.yml index a85cf579..322c2d88 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.1' services: mariadb: - image: 'mariadb:11.0' + image: 'mariadb:11' environment: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=acme diff --git a/tests/AppConfigMysql/config.yml b/tests/AppConfigMysql/config.yml index 21b15610..86952cee 100644 --- a/tests/AppConfigMysql/config.yml +++ b/tests/AppConfigMysql/config.yml @@ -8,3 +8,4 @@ doctrine: dbname: acme user: root password: root + server_version: '11' diff --git a/tests/AppConfigMysqlUrl/config.yml b/tests/AppConfigMysqlUrl/config.yml index 2cbdd85f..2ec48e8e 100644 --- a/tests/AppConfigMysqlUrl/config.yml +++ b/tests/AppConfigMysqlUrl/config.yml @@ -2,5 +2,5 @@ doctrine: dbal: - url: 'mysql://root:root@mariadb:3306/foobar' + url: 'mysql://root:root@mariadb:3306/foobar?serverVersion=11' driver: pdo_mysql diff --git a/tests/AppConfigPgsql/config.yml b/tests/AppConfigPgsql/config.yml index 21e362dc..1b6e052f 100644 --- a/tests/AppConfigPgsql/config.yml +++ b/tests/AppConfigPgsql/config.yml @@ -8,3 +8,4 @@ doctrine: dbname: postgres user: postgres password: postgres + server_version: '15' From 47f2a737452c619e67c98659467f010e85c691e2 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sat, 4 May 2024 15:34:18 +0200 Subject: [PATCH 3/3] chore: downgrade doctrine/dbal to 4 for PHP 8.1 --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c8cfbcb2..cf32b68b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,9 @@ jobs: - php-version: 8.1 # add a specific job to test ^5.4 for all Symfony packages symfony-version: "^5.4" + # `theofidry/alice-data-fixtures:1.6.0` and `doctrine/dbal:^4.0` cause issues: + # Error: Call to undefined method Doctrine\DBAL\Connection::exec() + composer-flags: "require doctrine/dbal:^3.0" - php-version: 8.2 symfony-version: "^7.0" - php-version: 8.3