@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.

Add a "--database <name> ..." flag to "bin/storage dump"

Summary: Ref T13671. Allow "bin/storage dump" to dump a subset of databases, primarily to support merging previously-partitioned databases.

Test Plan: Ran `bin/storage dump` with and without `--database ...` flags. Ran `--database invalid`, `--database a --database a` to hit error cases.

Maniphest Tasks: T13671

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

+72
+11
src/infrastructure/storage/management/PhabricatorStorageManagementAPI.php
··· 89 89 return $this->namespace.'_'.$fragment; 90 90 } 91 91 92 + public function getInternalDatabaseName($name) { 93 + $namespace = $this->getNamespace(); 94 + 95 + $prefix = $namespace.'_'; 96 + if (strncmp($name, $prefix, strlen($prefix))) { 97 + return null; 98 + } 99 + 100 + return substr($name, strlen($prefix)); 101 + } 102 + 92 103 public function getDisplayName() { 93 104 return $this->getRef()->getDisplayName(); 94 105 }
+61
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
··· 44 44 'With __--output__, overwrite the output file if it already '. 45 45 'exists.'), 46 46 ), 47 + array( 48 + 'name' => 'database', 49 + 'param' => 'database-name', 50 + 'help' => pht( 51 + 'Dump only tables in the named database (or databases, if '. 52 + 'the flag is repeated). Specify database names without the '. 53 + 'namespace prefix (that is: use "differential", not '. 54 + '"phabricator_differential").'), 55 + 'repeat' => true, 56 + ), 47 57 )); 48 58 } 49 59 ··· 57 67 $is_overwrite = $args->getArg('overwrite'); 58 68 $is_noindex = $args->getArg('no-indexes'); 59 69 $is_replica = $args->getArg('for-replica'); 70 + 71 + $database_filter = $args->getArg('database'); 60 72 61 73 if ($is_compress) { 62 74 if ($output_file === null) { ··· 128 140 $schemata = $actual_map[$ref_key]; 129 141 $expect = $expect_map[$ref_key]; 130 142 143 + if ($database_filter) { 144 + $internal_names = array(); 145 + 146 + $expect_databases = $expect->getDatabases(); 147 + foreach ($expect_databases as $expect_database) { 148 + $database_name = $expect_database->getName(); 149 + 150 + $internal_name = $api->getInternalDatabaseName($database_name); 151 + if ($internal_name !== null) { 152 + $internal_names[$internal_name] = $database_name; 153 + } 154 + } 155 + 156 + ksort($internal_names); 157 + 158 + $seen = array(); 159 + foreach ($database_filter as $filter) { 160 + if (!isset($internal_names[$filter])) { 161 + throw new PhutilArgumentUsageException( 162 + pht( 163 + 'Database "%s" is unknown. This script can only dump '. 164 + 'databases known to the current version of Phabricator. '. 165 + 'Valid databases are: %s.', 166 + $filter, 167 + implode(', ', array_keys($internal_names)))); 168 + } 169 + 170 + if (isset($seen[$filter])) { 171 + throw new PhutilArgumentUsageException( 172 + pht( 173 + 'Database "%s" is specified more than once. Specify each '. 174 + 'database at most once.', 175 + $filter)); 176 + } 177 + 178 + $seen[$filter] = true; 179 + } 180 + 181 + $dump_databases = array_select_keys($internal_names, $database_filter); 182 + $dump_databases = array_fuse($dump_databases); 183 + } else { 184 + $dump_databases = array_keys($schemata->getDatabases()); 185 + $dump_databases = array_fuse($dump_databases); 186 + } 187 + 131 188 $with_caches = $is_replica; 132 189 $with_indexes = !$is_noindex; 133 190 134 191 $targets = array(); 135 192 foreach ($schemata->getDatabases() as $database_name => $database) { 193 + if (!isset($dump_databases[$database_name])) { 194 + continue; 195 + } 196 + 136 197 $expect_database = $expect->getDatabase($database_name); 137 198 foreach ($database->getTables() as $table_name => $table) { 138 199