1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace App \Core \Infrastructure \Doctrine ;
6+
7+ use Doctrine \Bundle \DoctrineBundle \Attribute \AsDoctrineListener ;
8+ use Doctrine \Migrations \Metadata \Storage \TableMetadataStorageConfiguration ;
9+ use Doctrine \ORM \Tools \Event \GenerateSchemaEventArgs ;
10+ use Doctrine \ORM \Tools \ToolEvents ;
11+ use Symfony \Component \DependencyInjection \Attribute \Autowire ;
12+
13+ /** @see https://github.com/doctrine/migrations/issues/1406 */
14+ #[AsDoctrineListener(ToolEvents::postGenerateSchema)]
15+ final class FixDoctrineMigrationTableSchema
16+ {
17+ public function __construct (
18+ #[Autowire('@=service("doctrine.migrations.dependency_factory").getConfiguration().getMetadataStorageConfiguration() ' )]
19+ private TableMetadataStorageConfiguration $ configuration ,
20+ ) {
21+ }
22+
23+ /** @see \Doctrine\Migrations\Metadata\Storage\TableMetadataStorage::getExpectedTable */
24+ public function postGenerateSchema (GenerateSchemaEventArgs $ args ): void
25+ {
26+ $ schema = $ args ->getSchema ();
27+ $ schemaChangelog = $ schema ->createTable ($ this ->configuration ->getTableName ());
28+ $ schemaChangelog ->addColumn (
29+ $ this ->configuration ->getVersionColumnName (),
30+ 'string ' ,
31+ ['notnull ' => true , 'length ' => $ this ->configuration ->getVersionColumnLength ()],
32+ );
33+ $ schemaChangelog ->addColumn ($ this ->configuration ->getExecutedAtColumnName (), 'datetime ' , ['notnull ' => false ]);
34+ $ schemaChangelog ->addColumn ($ this ->configuration ->getExecutionTimeColumnName (), 'integer ' , ['notnull ' => false ]);
35+
36+ $ schemaChangelog ->setPrimaryKey ([$ this ->configuration ->getVersionColumnName ()]);
37+ }
38+ }
0 commit comments