Skip to content

Commit bb8091e

Browse files
committed
Migrate to column editor API
1 parent 0dd06c1 commit bb8091e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/Tools/SchemaTool.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Platforms\AbstractPlatform;
99
use Doctrine\DBAL\Schema\AbstractAsset;
1010
use Doctrine\DBAL\Schema\AbstractSchemaManager;
11+
use Doctrine\DBAL\Schema\ColumnEditor;
1112
use Doctrine\DBAL\Schema\ComparatorConfig;
1213
use Doctrine\DBAL\Schema\DefaultExpression;
1314
use Doctrine\DBAL\Schema\DefaultExpression\CurrentDate;
@@ -259,7 +260,18 @@ public function getSchemaFromMetadata(array $classes): Schema
259260
$this->platform,
260261
);
261262
// TODO: This seems rather hackish, can we optimize it?
262-
$table->getColumn($columnName)->setAutoincrement(false);
263+
// Use new column editor API only when new schema editor API is available (DBAL 4.5+)
264+
// @phpstan-ignore function.impossibleType (Using unreleased Schema::edit() API for version detection)
265+
if (method_exists(Schema::class, 'edit')) {
266+
// New API: modify column using table editor (creates new table object)
267+
// This is safe because we'll add the table to schema later after all modifications
268+
$table = $table->edit()->modifyColumnByUnquotedName(
269+
$columnName,
270+
static fn (ColumnEditor $column) => $column->setAutoincrement(false),
271+
)->create();
272+
} else {
273+
$table->getColumn($columnName)->setAutoincrement(false);
274+
}
263275

264276
$pkColumns[] = $columnName;
265277
$inheritedKeyColumns[] = $columnName;

0 commit comments

Comments
 (0)