diff --git a/drush/Commands/bc_dc/BcDcTestCleanupDrushCommands.php b/drush/Commands/bc_dc/BcDcTestCleanupDrushCommands.php new file mode 100644 index 00000000..0894868e --- /dev/null +++ b/drush/Commands/bc_dc/BcDcTestCleanupDrushCommands.php @@ -0,0 +1,59 @@ +output()->writeln($msg); + + $database = SqlBase::create(['db-url' => $db_url]); + + $query = 'DO + $do$ + BEGIN + EXECUTE ( + SELECT \'DROP TABLE \' || string_agg(format(\'%I.%I\', schemaname, tablename), \', \') + FROM ( + SELECT * + FROM pg_catalog.pg_tables t + WHERE schemaname NOT LIKE \'pg\_%\' -- Exclude system schemas. + AND tablename LIKE \'test%\' -- Prefix of tables to remove. + LIMIT 500 -- Limit to avoid running out of memory. + ) sub + ); + END + $do$;'; + + $success = $database->query($query); + + if ($success) { + $msg = dt('Done.'); + $this->output()->writeln($msg); + } + else { + throw new \Exception(dt('Query failed.')); + } + } + +}