Skip to content

Commit 9df13b7

Browse files
author
epriestley
committed
Provide a "-f" flag to scripts/sql/upgrade_schema.php
Summary: Normally this gives you a prompt about taking down services, provide a noninteractive mode for scripting the upgrade process. Also drop a generally bad/confusing/irrelevant piece of advice from the documentation and replace it with information about -f. Test Plan: Ran with and without -f. Ran with -h. Reviewers: moskov, tuomaspelkonen, jungejason, aran CC: Differential Revision: 387
1 parent df2cbf1 commit 9df13b7

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

scripts/sql/upgrade_schema.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,34 @@
2626

2727
define('SCHEMA_VERSION_TABLE_NAME', 'schema_version');
2828

29-
$options = getopt('v:u:p:') + array(
30-
'v' => null,
31-
'u' => null,
32-
'p' => null,
29+
// TODO: getopt() is super terrible, move to something less terrible.
30+
$options = getopt('fhv:u:p:') + array(
31+
'v' => null, // Upgrade from specific version
32+
'u' => null, // Override MySQL User
33+
'p' => null, // Override MySQL Pass
3334
);
3435

35-
if ($options['v'] && !is_numeric($options['v'])) {
36+
foreach (array('h', 'f') as $key) {
37+
// By default, these keys are set to 'false' to indicate that the flag was
38+
// passed.
39+
if (array_key_exists($key, $options)) {
40+
$options[$key] = true;
41+
}
42+
}
43+
44+
if (!empty($options['h']) || ($options['v'] && !is_numeric($options['v']))) {
3645
usage();
3746
}
3847

39-
echo phutil_console_wrap(
40-
"Before running this script, you should take down the Phabricator web ".
41-
"interface and stop any running Phabricator daemons.");
48+
if (empty($options['f'])) {
49+
echo phutil_console_wrap(
50+
"Before running this script, you should take down the Phabricator web ".
51+
"interface and stop any running Phabricator daemons.");
4252

43-
if (!phutil_console_confirm('Are you ready to continue?')) {
44-
echo "Cancelled.\n";
45-
exit(1);
53+
if (!phutil_console_confirm('Are you ready to continue?')) {
54+
echo "Cancelled.\n";
55+
exit(1);
56+
}
4657
}
4758

4859
// Use always the version from the commandline if it is defined
@@ -153,12 +164,14 @@
153164

154165
function usage() {
155166
echo
156-
"usage: upgrade_schema.php [-v version] [-u user -p pass]".
167+
"usage: upgrade_schema.php [-v version] [-u user -p pass] [-f] [-h]".
157168
"\n\n".
158-
"Run 'upgrade_schema.php -v 12' to apply all patches starting from ".
159-
"version 12.\n".
160169
"Run 'upgrade_schema.php -u root -p hunter2' to override the configured ".
161-
"default user.\n";
170+
"default user.\n".
171+
"Run 'upgrade_schema.php -v 12' to apply all patches starting from ".
172+
"version 12. It is very unlikely you need to do this.\n".
173+
"Use the -f flag to upgrade noninteractively, without prompting.\n".
174+
"Use the -h flag to show this help.\n";
162175
exit(1);
163176
}
164177

src/docs/upgrade_schema.diviner

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ root or some other admin user:
2323

2424
PHABRICATOR_ENV=<your_config> path/to/phabricator/scripts/sql/upgrade_schema.php -u <user> -p <pass>
2525

26-
If you need to upgrade the schema starting from a specific patch, just run:
26+
You can avoid the prompt the script issues by passing the ##-f## flag (for
27+
example, if you are scripting the upgrade process).
2728

28-
PHABRICATOR_ENV=<your_config> path/to/phabricator/scripts/sql/upgrade_schema.php -v <patch_number>
29-
30-
However, this isn't usually needed and could be dangerous!
29+
PHABRICATOR_ENV=<your_config> path/to/phabricator/scripts/sql/upgrade_schema.php -f

0 commit comments

Comments
 (0)