Skip to content

Commit e47a05a

Browse files
committed
Added support for doctrine/orm version 2
1 parent 23565c0 commit e47a05a

22 files changed

Lines changed: 606 additions & 268 deletions

.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export MYSQL_PASSWORD=test
1313
export MYSQL_DATABASE=testdb
1414
export MYSQL_VERSION=5.7
1515
export MYSQL_CHARSET=utf8
16+
export MYSQL_SERVER_VERSION=${MYSQL_VERSION}.0
1617

1718
export MARIADB_DRIVER=pdo_mysql
1819
export MARIADB_HOST=127.0.0.1
@@ -22,6 +23,7 @@ export MARIADB_PASSWORD=test
2223
export MARIADB_DATABASE=testdb
2324
export MARIADB_VERSION=11
2425
export MARIADB_CHARSET=utf8
26+
export MARIADB_SERVER_VERSION=${MYSQL_VERSION}.0
2527

2628
export MSSQL_DRIVER=pdo_sqlsrv
2729
export MSSQL_VERSION=2022

.github/workflows/ci.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888
strategy:
8989
matrix:
9090
mssql: ["2022"]
91+
composer_args: ["", "--prefer-lowest"]
9192

9293
steps:
9394
- uses: actions/checkout@v6
@@ -114,7 +115,7 @@ jobs:
114115
${{ runner.os }}-php-
115116
116117
- name: Install dependencies
117-
run: composer update --prefer-dist --no-progress --ignore-platform-reqs
118+
run: composer update --prefer-dist --no-progress --ignore-platform-reqs ${{ matrix.composer_args }}
118119

119120
- name: Start containers
120121
run: docker compose -f "docker-compose.yml" up -d --build mssql
@@ -160,10 +161,12 @@ jobs:
160161
MYSQL_PASSWORD: test
161162
MYSQL_DATABASE: testdb
162163
MYSQL_CHARSET: utf8
164+
MYSQL_SERVER_VERSION: ${{ matrix.mysql }}.0
163165

164166
strategy:
165167
matrix:
166168
mysql: ["9.5", "8.4", "5.7"]
169+
composer_args: ["", "--prefer-lowest"]
167170

168171
steps:
169172
- uses: actions/checkout@v6
@@ -183,7 +186,7 @@ jobs:
183186
${{ runner.os }}-php-
184187
185188
- name: Install dependencies
186-
run: composer update --prefer-dist --no-progress --ignore-platform-reqs
189+
run: composer update --prefer-dist --no-progress --ignore-platform-reqs ${{ matrix.composer_args }}
187190

188191
- name: Start containers
189192
run: docker compose -f "docker-compose.yml" up -d --build mysql
@@ -229,10 +232,12 @@ jobs:
229232
MARIADB_PASSWORD: test
230233
MARIADB_DATABASE: testdb
231234
MARIADB_CHARSET: utf8
235+
MARIADB_SERVER_VERSION: 5.7.0
232236

233237
strategy:
234238
matrix:
235239
mariadb: ["12", "11"]
240+
composer_args: ["", "--prefer-lowest"]
236241

237242
steps:
238243
- uses: actions/checkout@v6
@@ -252,7 +257,7 @@ jobs:
252257
${{ runner.os }}-php-
253258
254259
- name: Install dependencies
255-
run: composer update --prefer-dist --no-progress --ignore-platform-reqs
260+
run: composer update --prefer-dist --no-progress --ignore-platform-reqs ${{ matrix.composer_args }}
256261

257262
- name: Start containers
258263
run: docker compose -f "docker-compose.yml" up -d --build mariadb
@@ -301,6 +306,7 @@ jobs:
301306
strategy:
302307
matrix:
303308
postgres: ["18", "17", "16", "15", "14"]
309+
composer_args: ["", "--prefer-lowest"]
304310

305311
steps:
306312
- uses: actions/checkout@v6
@@ -320,7 +326,7 @@ jobs:
320326
${{ runner.os }}-php-
321327
322328
- name: Install dependencies
323-
run: composer update --prefer-dist --no-progress --ignore-platform-reqs
329+
run: composer update --prefer-dist --no-progress --ignore-platform-reqs ${{ matrix.composer_args }}
324330

325331
- name: Start containers
326332
run: docker compose -f "docker-compose.yml" up -d --build postgresql

behat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'user' => getenv('MYSQL_USER'),
2323
'password' => getenv('MYSQL_PASSWORD'),
2424
'charset' => getenv('MYSQL_CHARSET'),
25-
'serverVersion' => getenv('MYSQL_SERVER_VERSION'),
25+
'serverVersion' => getenv('MYSQL_SERVER_VERSION'),
2626
])
2727
->addContext(MariaDBContext::class, [
2828
'driver' => getenv('MARIADB_DRIVER'),
@@ -32,7 +32,7 @@
3232
'user' => getenv('MARIADB_USER'),
3333
'password' => getenv('MARIADB_PASSWORD'),
3434
'charset' => getenv('MARIADB_CHARSET'),
35-
'serverVersion' => getenv('MARIADB_SERVER_VERSION'),
35+
'serverVersion' => getenv('MARIADB_SERVER_VERSION'),
3636
])
3737
->addContext(PostgreSQLContext::class, [
3838
'driver' => getenv('POSTGRES_DRIVER'),

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
},
2121
"autoload-dev": {
2222
"psr-4": {
23-
"Fabiang\\Doctrine\\Migrations\\Liquibase\\": "tests/features/bootstrap",
24-
"Fabiang\\Doctrine\\Migrations\\Liquibase\\Entity\\": "tests/features/Entitiy"
23+
"Fabiang\\Doctrine\\Migrations\\Liquibase\\": [
24+
"tests/features/bootstrap",
25+
"tests/units/src"
26+
],
27+
"Fabiang\\Doctrine\\Migrations\\Liquibase\\Entity\\": "tests/features/Entity"
2528
}
2629
},
2730
"require": {
2831
"php": "~8.3.0 || ~8.4.0",
29-
"doctrine/orm": "^3.0",
30-
"doctrine/dbal": "^4.3"
32+
"doctrine/orm": "^2.20 || ^3.0",
33+
"doctrine/dbal": "^3.10 || ^4.3"
3134
},
3235
"require-dev": {
3336
"phpunit/phpunit": "^12.4",

src/Helper/VersionHelper.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fabiang\Doctrine\Migrations\Liquibase\Helper;
6+
7+
use Composer\InstalledVersions;
8+
use Composer\Semver\VersionParser;
9+
10+
final class VersionHelper
11+
{
12+
private static ?bool $dbalVersion4 = null;
13+
14+
public static function isDBALVersion4(): bool
15+
{
16+
if (static::$dbalVersion4 === null) {
17+
static::$dbalVersion4 = InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '^4.0');
18+
}
19+
20+
return static::$dbalVersion4;
21+
}
22+
}

src/LiquibaseSchemaTool.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Fabiang\Doctrine\Migrations\Liquibase;
66

77
use Doctrine\DBAL\Schema\Comparator;
8+
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
89
use Doctrine\DBAL\Schema\Schema;
910
use Doctrine\DBAL\Schema\SchemaDiff;
1011
use Doctrine\ORM\EntityManagerInterface;
@@ -130,7 +131,13 @@ public function diffChangeLogFromSchemaDiff(
130131
$soutput->alterTable($tableDiff);
131132

132133
foreach ($tableDiff->getDroppedForeignKeys() as $foreignKey) {
133-
$soutput->dropForeignKey($foreignKey, $tableDiff->getOldTable());
134+
$oldTable = $tableDiff->getOldTable();
135+
/**
136+
* @psalm-suppress RedundantCondition
137+
*/
138+
if ($foreignKey instanceof ForeignKeyConstraint && $oldTable !== null) {
139+
$soutput->dropForeignKey($foreignKey, $oldTable);
140+
}
134141
}
135142
}
136143

0 commit comments

Comments
 (0)