13
13
14
14
use Doctrine \DBAL \Connection ;
15
15
use Doctrine \DBAL \Exception \TableNotFoundException ;
16
+ use Doctrine \DBAL \Schema \Table ;
17
+ use Doctrine \DBAL \Types \Types ;
16
18
use Doctrine \ORM \Tools \Event \GenerateSchemaEventArgs ;
17
19
18
20
abstract class AbstractSchemaListener
@@ -22,8 +24,16 @@ abstract public function postGenerateSchema(GenerateSchemaEventArgs $event): voi
22
24
protected function getIsSameDatabaseChecker (Connection $ connection ): \Closure
23
25
{
24
26
return static function (\Closure $ exec ) use ($ connection ): bool {
27
+ $ schemaManager = $ connection ->createSchemaManager ();
28
+
25
29
$ checkTable = 'schema_subscriber_check_ ' .bin2hex (random_bytes (7 ));
26
- $ connection ->executeStatement (sprintf ('CREATE TABLE %s (id INTEGER NOT NULL) ' , $ checkTable ));
30
+ $ table = new Table ($ checkTable );
31
+ $ table ->addColumn ('id ' , Types::INTEGER )
32
+ ->setAutoincrement (true )
33
+ ->setNotnull (true );
34
+ $ table ->setPrimaryKey (['id ' ]);
35
+
36
+ $ schemaManager ->createTable ($ table );
27
37
28
38
try {
29
39
$ exec (sprintf ('DROP TABLE %s ' , $ checkTable ));
@@ -32,7 +42,7 @@ protected function getIsSameDatabaseChecker(Connection $connection): \Closure
32
42
}
33
43
34
44
try {
35
- $ connection -> executeStatement ( sprintf ( ' DROP TABLE %s ' , $ checkTable) );
45
+ $ schemaManager -> dropTable ( $ checkTable );
36
46
37
47
return false ;
38
48
} catch (TableNotFoundException ) {
0 commit comments