@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Delete stale fixtures with bin/storage destroy

Summary:
When a PhabricatorTestCase dies after creating storage fixtures, it leaves
those storage fixtures around. This doesn't happen often, but when it does
happen it's a pain to cleanup. The --unittest-fixtures option helps automate
that cleanup.

Test Plan:
Ran it with --dryrun, then for real. Became overwhelmed with a Zen like peace
after regarding the tidiness and beauty of SHOW DATABASES.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3858

+24 -4
+22 -3
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDestroyWorkflow.php
··· 23 23 $this 24 24 ->setName('destroy') 25 25 ->setExamples('**destroy** [__options__]') 26 - ->setSynopsis('Permanently destroy all storage and data.'); 26 + ->setSynopsis('Permanently destroy all storage and data.') 27 + ->setArguments( 28 + array( 29 + array( 30 + 'name' => 'unittest-fixtures', 31 + 'help' => "Restrict **destroy** operations to databases created ". 32 + "by PhabricatorTestCase test fixtures.", 33 + ))); 27 34 } 28 35 29 36 public function execute(PhutilArgumentParser $args) { ··· 50 57 $api = $this->getAPI(); 51 58 $patches = $this->getPatches(); 52 59 53 - $databases = $api->getDatabaseList($patches); 54 - $databases[] = $api->getDatabaseName('meta_data'); 60 + if ($args->getArg('unittest-fixtures')) { 61 + $conn = $api->getConn(null, false); 62 + $databases = queryfx_all( 63 + $conn, 64 + 'SELECT DISTINCT(TABLE_SCHEMA) AS db '. 65 + 'FROM INFORMATION_SCHEMA.TABLES '. 66 + 'WHERE TABLE_SCHEMA LIKE %>', 67 + PhabricatorTestCase::NAMESPACE_PREFIX); 68 + $databases = ipull($databases, 'db'); 69 + } else { 70 + $databases = $api->getDatabaseList($patches); 71 + $databases[] = $api->getDatabaseName('meta_data'); 72 + } 73 + 55 74 foreach ($databases as $database) { 56 75 if ($is_dry) { 57 76 echo "DRYRUN: Would drop database '{$database}'.\n";
+2 -1
src/infrastructure/testing/PhabricatorTestCase.php
··· 18 18 19 19 abstract class PhabricatorTestCase extends ArcanistPhutilTestCase { 20 20 21 + const NAMESPACE_PREFIX = 'phabricator_unittest_'; 21 22 22 23 /** 23 24 * If true, put Lisk in process-isolated mode for the duration of the tests so ··· 132 133 133 134 protected function newStorageFixture() { 134 135 $bytes = Filesystem::readRandomCharacters(24); 135 - $name = 'phabricator_unittest_'.$bytes; 136 + $name = self::NAMESPACE_PREFIX.$bytes; 136 137 137 138 return new PhabricatorStorageFixtureScopeGuard($name); 138 139 }