@@ -291,7 +291,16 @@ function compareTableSchemas(string $tableName, Doctrine\DBAL\Schema\Table $expe
291291function cleanupTableManagerTestTables (): void
292292{
293293 try {
294- db ()->getConnection ()->executeStatement ('DROP TABLE IF EXISTS user CASCADE; ' );
294+ $ connection = db ()->getConnection ();
295+ $ platform = $ connection ->getDatabasePlatform ();
296+
297+ if ($ platform instanceof \Doctrine \DBAL \Platforms \SqlitePlatform) {
298+ $ connection ->executeStatement ('DROP TABLE IF EXISTS user; ' );
299+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \PostgreSQLPlatform) {
300+ $ connection ->executeStatement ('DROP TABLE IF EXISTS "user" CASCADE; ' );
301+ } else {
302+ $ connection ->executeStatement ('DROP TABLE IF EXISTS user CASCADE; ' );
303+ }
295304 } catch (Exception ) {
296305 // Ignore cleanup errors
297306 }
@@ -417,17 +426,42 @@ function cleanupTestTables(string $useUUID): void
417426{
418427 try {
419428 $ connection = db ($ useUUID )->getConnection ();
420- $ connection ->executeStatement ('SET FOREIGN_KEY_CHECKS=0; ' );
429+ $ platform = $ connection ->getDatabasePlatform ();
430+
431+ // Disable foreign key checks if supported
432+ if ($ platform instanceof \Doctrine \DBAL \Platforms \MySQLPlatform) {
433+ $ connection ->executeStatement ('SET FOREIGN_KEY_CHECKS=0; ' );
434+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \SqlitePlatform) {
435+ $ connection ->executeStatement ('PRAGMA foreign_keys = OFF; ' );
436+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \PostgreSQLPlatform) {
437+ // PostgreSQL doesn't have a global foreign key disable,
438+ // but CASCADE in DROP statements handles dependencies
439+ }
421440
422441 // Get all existing tables first
423442 $ tables = $ connection ->createSchemaManager ()->listTableNames ();
424443
425444 // Drop all tables to ensure complete cleanup
426445 foreach ($ tables as $ table ) {
427- $ connection ->executeStatement ("DROP TABLE IF EXISTS {$ table } CASCADE; " );
446+ if ($ platform instanceof \Doctrine \DBAL \Platforms \MySQLPlatform) {
447+ $ connection ->executeStatement ("DROP TABLE IF EXISTS {$ table } CASCADE; " );
448+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \SqlitePlatform) {
449+ $ connection ->executeStatement ("DROP TABLE IF EXISTS {$ table }; " );
450+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \PostgreSQLPlatform) {
451+ $ connection ->executeStatement ("DROP TABLE IF EXISTS \"{$ table }\" CASCADE; " );
452+ } else {
453+ $ connection ->executeStatement ("DROP TABLE IF EXISTS {$ table } CASCADE; " );
454+ }
428455 }
429456
430- $ connection ->executeStatement ('SET FOREIGN_KEY_CHECKS=1; ' );
457+ // Re-enable foreign key checks if supported
458+ if ($ platform instanceof \Doctrine \DBAL \Platforms \MySQLPlatform) {
459+ $ connection ->executeStatement ('SET FOREIGN_KEY_CHECKS=1; ' );
460+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \SqlitePlatform) {
461+ $ connection ->executeStatement ('PRAGMA foreign_keys = ON; ' );
462+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \PostgreSQLPlatform) {
463+ // No global setting to re-enable for PostgreSQL
464+ }
431465 } catch (Exception ) {
432466 // Ignore cleanup errors
433467 }
@@ -442,17 +476,41 @@ function cleanupAllTestTables(): void
442476 foreach (['UUID ' , 'ID ' ] as $ config ) {
443477 try {
444478 $ connection = db ($ config )->getConnection ();
445- $ connection ->executeStatement ('SET FOREIGN_KEY_CHECKS=0; ' );
479+ $ platform = $ connection ->getDatabasePlatform ();
480+
481+ // Disable foreign key checks if supported
482+ if ($ platform instanceof \Doctrine \DBAL \Platforms \MySQLPlatform) {
483+ $ connection ->executeStatement ('SET FOREIGN_KEY_CHECKS=0; ' );
484+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \SqlitePlatform) {
485+ $ connection ->executeStatement ('PRAGMA foreign_keys = OFF; ' );
486+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \PostgreSQLPlatform) {
487+ // PostgreSQL doesn't have a global foreign key disable
488+ }
446489
447490 // Get all existing tables first
448491 $ tables = $ connection ->createSchemaManager ()->listTableNames ();
449492
450493 // Drop all tables to ensure complete cleanup
451494 foreach ($ tables as $ table ) {
452- $ connection ->executeStatement ("DROP TABLE IF EXISTS {$ table } CASCADE; " );
495+ if ($ platform instanceof \Doctrine \DBAL \Platforms \MySQLPlatform) {
496+ $ connection ->executeStatement ("DROP TABLE IF EXISTS {$ table } CASCADE; " );
497+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \SqlitePlatform) {
498+ $ connection ->executeStatement ("DROP TABLE IF EXISTS {$ table }; " );
499+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \PostgreSQLPlatform) {
500+ $ connection ->executeStatement ("DROP TABLE IF EXISTS \"{$ table }\" CASCADE; " );
501+ } else {
502+ $ connection ->executeStatement ("DROP TABLE IF EXISTS {$ table } CASCADE; " );
503+ }
453504 }
454505
455- $ connection ->executeStatement ('SET FOREIGN_KEY_CHECKS=1; ' );
506+ // Re-enable foreign key checks if supported
507+ if ($ platform instanceof \Doctrine \DBAL \Platforms \MySQLPlatform) {
508+ $ connection ->executeStatement ('SET FOREIGN_KEY_CHECKS=1; ' );
509+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \SqlitePlatform) {
510+ $ connection ->executeStatement ('PRAGMA foreign_keys = ON; ' );
511+ } elseif ($ platform instanceof \Doctrine \DBAL \Platforms \PostgreSQLPlatform) {
512+ // No global setting to re-enable for PostgreSQL
513+ }
456514 } catch (Exception ) {
457515 // Ignore cleanup errors
458516 }
0 commit comments