Skip to content

Commit 237b1d7

Browse files
author
epriestley
committedAug 8, 2014
Improve bin/storage upgrade behavior when run out-of-order
Summary: Fixes T5770. This error occurs if you run `bin/storage upgrade` before you set up MySQL credentials. This isn't what the setup guide says to do, but it's an easy mistake to make and should be a permitted install path since there's no reason you can't do things in this order. Specifically, we use a mixture of "standard" (configured) and "administrative" (`--user` and `--password`) credentials, and if the standard ones are bogus bad things happen. We use the standard credentials to make some initialization order stuff easier, and because there's no `--host` flag and adding one would be silly, and because we only need administrative credentials to issue ALTER / CREATE statements. Test Plan: Ran with bad standard credentials; ran with bad administrative credentials. Ran with good credentials. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5770 Differential Revision: https://secure.phabricator.com/D10199
1 parent cda397d commit 237b1d7

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed
 

‎scripts/sql/manage_storage.php

+52-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,46 @@
7070
exit(77);
7171
}
7272

73+
// First, test that the Phabricator configuration is set up correctly. After
74+
// we know this works we'll test any administrative credentials specifically.
75+
76+
$test_api = new PhabricatorStorageManagementAPI();
77+
$test_api->setUser($default_user);
78+
$test_api->setHost($default_host);
79+
$test_api->setPort($default_port);
80+
$test_api->setPassword($conf->getPassword());
81+
$test_api->setNamespace($args->getArg('namespace'));
82+
83+
try {
84+
queryfx(
85+
$test_api->getConn(null),
86+
'SELECT 1');
87+
} catch (AphrontQueryException $ex) {
88+
$message = phutil_console_format(
89+
pht(
90+
"**MySQL Credentials Not Configured**\n\n".
91+
"Unable to connect to MySQL using the configured credentials. ".
92+
"You must configure standard credentials before you can upgrade ".
93+
"storage. Run these commands to set up credentials:\n".
94+
"\n".
95+
" phabricator/ $ ./bin/config set mysql.host __host__\n".
96+
" phabricator/ $ ./bin/config set mysql.user __username__\n".
97+
" phabricator/ $ ./bin/config set mysql.pass __password__\n".
98+
"\n".
99+
"These standard credentials are separate from any administrative ".
100+
"credentials provided to this command with __--user__ or ".
101+
"__--password__, and must be configured correctly before you can ".
102+
"proceed.\n".
103+
"\n".
104+
"**Raw MySQL Error**: %s\n",
105+
$ex->getMessage()));
106+
107+
echo phutil_console_wrap($message);
108+
109+
exit(1);
110+
}
111+
112+
73113
if ($args->getArg('password') === null) {
74114
// This is already a PhutilOpaqueEnvelope.
75115
$password = $conf->getPassword();
@@ -92,10 +132,18 @@
92132
$api->getConn(null),
93133
'SELECT 1');
94134
} catch (AphrontQueryException $ex) {
95-
echo phutil_console_format(
96-
"**%s**: %s\n",
97-
'Unable To Connect',
98-
$ex->getMessage());
135+
$message = phutil_console_format(
136+
pht(
137+
"**Bad Administrative Credentials**\n\n".
138+
"Unable to connnect to MySQL using the administrative credentials ".
139+
"provided with the __--user__ and __--password__ flags. Check that ".
140+
"you have entered them correctly.\n".
141+
"\n".
142+
"**Raw MySQL Error**: %s\n",
143+
$ex->getMessage()));
144+
145+
echo phutil_console_wrap($message);
146+
99147
exit(1);
100148
}
101149

0 commit comments

Comments
 (0)
Failed to load comments.