From 237b1d769b0085a3177da9a5f7c5b619ddb7225a Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 8 Aug 2014 15:44:40 -0700 Subject: [PATCH] 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 --- scripts/sql/manage_storage.php | 56 +++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/scripts/sql/manage_storage.php b/scripts/sql/manage_storage.php index a94ee75f3c..0b0b6da9b1 100755 --- a/scripts/sql/manage_storage.php +++ b/scripts/sql/manage_storage.php @@ -70,6 +70,46 @@ try { exit(77); } +// First, test that the Phabricator configuration is set up correctly. After +// we know this works we'll test any administrative credentials specifically. + +$test_api = new PhabricatorStorageManagementAPI(); +$test_api->setUser($default_user); +$test_api->setHost($default_host); +$test_api->setPort($default_port); +$test_api->setPassword($conf->getPassword()); +$test_api->setNamespace($args->getArg('namespace')); + +try { + queryfx( + $test_api->getConn(null), + 'SELECT 1'); +} catch (AphrontQueryException $ex) { + $message = phutil_console_format( + pht( + "**MySQL Credentials Not Configured**\n\n". + "Unable to connect to MySQL using the configured credentials. ". + "You must configure standard credentials before you can upgrade ". + "storage. Run these commands to set up credentials:\n". + "\n". + " phabricator/ $ ./bin/config set mysql.host __host__\n". + " phabricator/ $ ./bin/config set mysql.user __username__\n". + " phabricator/ $ ./bin/config set mysql.pass __password__\n". + "\n". + "These standard credentials are separate from any administrative ". + "credentials provided to this command with __--user__ or ". + "__--password__, and must be configured correctly before you can ". + "proceed.\n". + "\n". + "**Raw MySQL Error**: %s\n", + $ex->getMessage())); + + echo phutil_console_wrap($message); + + exit(1); +} + + if ($args->getArg('password') === null) { // This is already a PhutilOpaqueEnvelope. $password = $conf->getPassword(); @@ -92,10 +132,18 @@ try { $api->getConn(null), 'SELECT 1'); } catch (AphrontQueryException $ex) { - echo phutil_console_format( - "**%s**: %s\n", - 'Unable To Connect', - $ex->getMessage()); + $message = phutil_console_format( + pht( + "**Bad Administrative Credentials**\n\n". + "Unable to connnect to MySQL using the administrative credentials ". + "provided with the __--user__ and __--password__ flags. Check that ". + "you have entered them correctly.\n". + "\n". + "**Raw MySQL Error**: %s\n", + $ex->getMessage())); + + echo phutil_console_wrap($message); + exit(1); }