1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace App \Core \Infrastructure \Doctrine ;
6
+
7
+ use Doctrine \DBAL \Exception ;
8
+ use Doctrine \DBAL \Schema \SchemaException ;
9
+ use Doctrine \Migrations \DependencyFactory ;
10
+ use Doctrine \Migrations \Metadata \Storage \TableMetadataStorageConfiguration ;
11
+ use Doctrine \ORM \Tools \Event \GenerateSchemaEventArgs ;
12
+ use Webmozart \Assert \Assert ;
13
+
14
+ /** @see https://github.com/doctrine/migrations/issues/1406 */
15
+ final class FixDoctrineMigrationTableSchema
16
+ {
17
+ private TableMetadataStorageConfiguration $ configuration ;
18
+
19
+ public function __construct (
20
+ private readonly DependencyFactory $ dependencyFactory ,
21
+ ) {
22
+ $ configuration = $ this ->dependencyFactory ->getConfiguration ()->getMetadataStorageConfiguration ();
23
+
24
+ Assert::notNull ($ configuration );
25
+ Assert::isInstanceOf ($ configuration , TableMetadataStorageConfiguration::class);
26
+
27
+ $ this ->configuration = $ configuration ;
28
+ }
29
+
30
+ /**
31
+ * @throws SchemaException
32
+ * @throws Exception
33
+ */
34
+ public function postGenerateSchema (GenerateSchemaEventArgs $ args ): void
35
+ {
36
+ $ schema = $ args ->getSchema ();
37
+ $ table = $ schema ->createTable ($ this ->configuration ->getTableName ());
38
+ $ table ->addColumn (
39
+ $ this ->configuration ->getVersionColumnName (),
40
+ 'string ' ,
41
+ ['notnull ' => true , 'length ' => $ this ->configuration ->getVersionColumnLength ()],
42
+ );
43
+ $ table ->addColumn ($ this ->configuration ->getExecutedAtColumnName (), 'datetime ' , ['notnull ' => false ]);
44
+ $ table ->addColumn ($ this ->configuration ->getExecutionTimeColumnName (), 'integer ' , ['notnull ' => false ]);
45
+
46
+ $ table ->setPrimaryKey ([$ this ->configuration ->getVersionColumnName ()]);
47
+ }
48
+ }
0 commit comments