diff --git a/scripts/sql/upgrade_schema.php b/scripts/sql/upgrade_schema.php index 39b589a6dc..104dc6b027 100755 --- a/scripts/sql/upgrade_schema.php +++ b/scripts/sql/upgrade_schema.php @@ -1,164 +1,177 @@ #!/usr/bin/env php null, - 'u' => null, - 'p' => null, +// TODO: getopt() is super terrible, move to something less terrible. +$options = getopt('fhv:u:p:') + array( + 'v' => null, // Upgrade from specific version + 'u' => null, // Override MySQL User + 'p' => null, // Override MySQL Pass ); -if ($options['v'] && !is_numeric($options['v'])) { +foreach (array('h', 'f') as $key) { + // By default, these keys are set to 'false' to indicate that the flag was + // passed. + if (array_key_exists($key, $options)) { + $options[$key] = true; + } +} + +if (!empty($options['h']) || ($options['v'] && !is_numeric($options['v']))) { usage(); } -echo phutil_console_wrap( - "Before running this script, you should take down the Phabricator web ". - "interface and stop any running Phabricator daemons."); +if (empty($options['f'])) { + echo phutil_console_wrap( + "Before running this script, you should take down the Phabricator web ". + "interface and stop any running Phabricator daemons."); -if (!phutil_console_confirm('Are you ready to continue?')) { - echo "Cancelled.\n"; - exit(1); + if (!phutil_console_confirm('Are you ready to continue?')) { + echo "Cancelled.\n"; + exit(1); + } } // Use always the version from the commandline if it is defined $next_version = isset($options['v']) ? (int)$options['v'] : null; if ($options['u']) { $conn_user = $options['u']; $conn_pass = $options['p']; } else { $conn_user = PhabricatorEnv::getEnvConfig('mysql.user'); $conn_pass = PhabricatorEnv::getEnvConfig('mysql.pass'); } $conn_host = PhabricatorEnv::getEnvConfig('mysql.host'); $conn = new AphrontMySQLDatabaseConnection( array( 'user' => $conn_user, 'pass' => $conn_pass, 'host' => $conn_host, 'database' => null, )); try { $create_sql = <<getMessage(). "\n\n"; exit(1); } function usage() { echo - "usage: upgrade_schema.php [-v version] [-u user -p pass]". + "usage: upgrade_schema.php [-v version] [-u user -p pass] [-f] [-h]". "\n\n". - "Run 'upgrade_schema.php -v 12' to apply all patches starting from ". - "version 12.\n". "Run 'upgrade_schema.php -u root -p hunter2' to override the configured ". - "default user.\n"; + "default user.\n". + "Run 'upgrade_schema.php -v 12' to apply all patches starting from ". + "version 12. It is very unlikely you need to do this.\n". + "Use the -f flag to upgrade noninteractively, without prompting.\n". + "Use the -h flag to show this help.\n"; exit(1); } diff --git a/src/docs/upgrade_schema.diviner b/src/docs/upgrade_schema.diviner index 80200d4510..be4146b384 100644 --- a/src/docs/upgrade_schema.diviner +++ b/src/docs/upgrade_schema.diviner @@ -1,30 +1,29 @@ @title Upgrading Schema @group config This document describes how to upgrade the database schema. = Prerequisites = This document assumes you've already initialized the MySQL database and configured your Phabricator environment. If you haven't, see @{article:Configuration Guide}. = Loading patches = To upgrade your database schema to the latest version, just run this command: PHABRICATOR_ENV= path/to/phabricator/scripts/sql/upgrade_schema.php This will install all the patches that are new since you installed, or since the last time you ran this script. If your configuration uses an unprivileged user to connect to the database, you may have to override the default user so the schema changes can be applied with root or some other admin user: PHABRICATOR_ENV= path/to/phabricator/scripts/sql/upgrade_schema.php -u -p -If you need to upgrade the schema starting from a specific patch, just run: +You can avoid the prompt the script issues by passing the ##-f## flag (for +example, if you are scripting the upgrade process). - PHABRICATOR_ENV= path/to/phabricator/scripts/sql/upgrade_schema.php -v - -However, this isn't usually needed and could be dangerous! + PHABRICATOR_ENV= path/to/phabricator/scripts/sql/upgrade_schema.php -f