diff --git a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php index 5bc13ecd94..ce1c9c8d80 100644 --- a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php +++ b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php @@ -23,7 +23,14 @@ final class PhabricatorStorageManagementDestroyWorkflow $this ->setName('destroy') ->setExamples('**destroy** [__options__]') - ->setSynopsis('Permanently destroy all storage and data.'); + ->setSynopsis('Permanently destroy all storage and data.') + ->setArguments( + array( + array( + 'name' => 'unittest-fixtures', + 'help' => "Restrict **destroy** operations to databases created ". + "by PhabricatorTestCase test fixtures.", + ))); } public function execute(PhutilArgumentParser $args) { @@ -50,8 +57,20 @@ final class PhabricatorStorageManagementDestroyWorkflow $api = $this->getAPI(); $patches = $this->getPatches(); - $databases = $api->getDatabaseList($patches); - $databases[] = $api->getDatabaseName('meta_data'); + if ($args->getArg('unittest-fixtures')) { + $conn = $api->getConn(null, false); + $databases = queryfx_all( + $conn, + 'SELECT DISTINCT(TABLE_SCHEMA) AS db '. + 'FROM INFORMATION_SCHEMA.TABLES '. + 'WHERE TABLE_SCHEMA LIKE %>', + PhabricatorTestCase::NAMESPACE_PREFIX); + $databases = ipull($databases, 'db'); + } else { + $databases = $api->getDatabaseList($patches); + $databases[] = $api->getDatabaseName('meta_data'); + } + foreach ($databases as $database) { if ($is_dry) { echo "DRYRUN: Would drop database '{$database}'.\n"; diff --git a/src/infrastructure/testing/PhabricatorTestCase.php b/src/infrastructure/testing/PhabricatorTestCase.php index ca614f4cfb..8d2582d9a9 100644 --- a/src/infrastructure/testing/PhabricatorTestCase.php +++ b/src/infrastructure/testing/PhabricatorTestCase.php @@ -18,6 +18,7 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase { + const NAMESPACE_PREFIX = 'phabricator_unittest_'; /** * If true, put Lisk in process-isolated mode for the duration of the tests so @@ -132,7 +133,7 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase { protected function newStorageFixture() { $bytes = Filesystem::readRandomCharacters(24); - $name = 'phabricator_unittest_'.$bytes; + $name = self::NAMESPACE_PREFIX.$bytes; return new PhabricatorStorageFixtureScopeGuard($name); }