|
17 | 17 | * limitations under the License.
|
18 | 18 | */
|
19 | 19 |
|
20 |
| -$root = dirname(dirname(dirname(__FILE__))); |
21 |
| -require_once $root.'/scripts/__init_script__.php'; |
22 |
| - |
23 |
| -phutil_require_module('phutil', 'console'); |
24 |
| -phutil_require_module('phabricator', 'infrastructure/setup/sql'); |
25 |
| - |
26 |
| -define('SCHEMA_VERSION_TABLE_NAME', 'schema_version'); |
27 |
| - |
28 |
| -// TODO: getopt() is super terrible, move to something less terrible. |
29 |
| -$options = getopt('fhdv:u:p:m:') + array( |
30 |
| - 'v' => null, // Upgrade from specific version |
31 |
| - 'u' => null, // Override MySQL User |
32 |
| - 'p' => null, // Override MySQL Pass |
33 |
| - 'm' => null, // Specify max version to upgrade to |
34 |
| -); |
35 |
| - |
36 |
| -foreach (array('h', 'f', 'd') 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'])) |
45 |
| - || ($options['m'] && !is_numeric($options['m']))) { |
46 |
| - usage(); |
47 |
| -} |
48 |
| - |
49 |
| -if (empty($options['f']) && empty($options['d'])) { |
50 |
| - echo phutil_console_wrap( |
51 |
| - "Before running this script, you should take down the Phabricator web ". |
52 |
| - "interface and stop any running Phabricator daemons."); |
53 |
| - |
54 |
| - if (!phutil_console_confirm('Are you ready to continue?')) { |
55 |
| - echo "Cancelled.\n"; |
56 |
| - exit(1); |
57 |
| - } |
58 |
| -} |
59 |
| - |
60 |
| -// Use always the version from the commandline if it is defined |
61 |
| -$next_version = isset($options['v']) ? (int)$options['v'] : null; |
62 |
| -$max_version = isset($options['m']) ? (int)$options['m'] : null; |
63 |
| - |
64 |
| -$conf = PhabricatorEnv::newObjectFromConfig('mysql.configuration-provider'); |
65 |
| - |
66 |
| -if ($options['u']) { |
67 |
| - $conn_user = $options['u']; |
68 |
| - $conn_pass = $options['p']; |
69 |
| -} else { |
70 |
| - $conn_user = $conf->getUser(); |
71 |
| - $conn_pass = $conf->getPassword(); |
72 |
| -} |
73 |
| -$conn_host = $conf->getHost(); |
74 |
| - |
75 |
| -// Split out port information, since the command-line client requires a |
76 |
| -// separate flag for the port. |
77 |
| -$uri = new PhutilURI('mysql://'.$conn_host); |
78 |
| -if ($uri->getPort()) { |
79 |
| - $conn_port = $uri->getPort(); |
80 |
| - $conn_bare_hostname = $uri->getDomain(); |
81 |
| -} else { |
82 |
| - $conn_port = null; |
83 |
| - $conn_bare_hostname = $conn_host; |
84 |
| -} |
85 |
| - |
86 |
| -$conn = PhabricatorEnv::newObjectFromConfig( |
87 |
| - 'mysql.implementation', |
88 |
| - array( |
89 |
| - array( |
90 |
| - 'user' => $conn_user, |
91 |
| - 'pass' => $conn_pass, |
92 |
| - 'host' => $conn_host, |
93 |
| - 'database' => null, |
94 |
| - ), |
95 |
| - )); |
96 |
| - |
97 |
| -try { |
98 |
| - |
99 |
| - $create_sql = <<<END |
100 |
| - CREATE DATABASE IF NOT EXISTS `phabricator_meta_data`; |
101 |
| -END; |
102 |
| - queryfx($conn, $create_sql); |
103 |
| - |
104 |
| - $create_sql = <<<END |
105 |
| - CREATE TABLE IF NOT EXISTS phabricator_meta_data.`schema_version` ( |
106 |
| - `version` INTEGER not null |
107 |
| - ); |
108 |
| -END; |
109 |
| - queryfx($conn, $create_sql); |
110 |
| - |
111 |
| - // Get the version only if commandline argument wasn't given |
112 |
| - if ($next_version === null) { |
113 |
| - $version = queryfx_one( |
114 |
| - $conn, |
115 |
| - 'SELECT * FROM phabricator_meta_data.%T', |
116 |
| - SCHEMA_VERSION_TABLE_NAME); |
117 |
| - |
118 |
| - if (!$version) { |
119 |
| - print "*** No version information in the database ***\n"; |
120 |
| - print "*** Give the first patch version which to ***\n"; |
121 |
| - print "*** apply as the command line argument ***\n"; |
122 |
| - exit(-1); |
123 |
| - } |
124 |
| - |
125 |
| - $next_version = $version['version'] + 1; |
126 |
| - } |
127 |
| - |
128 |
| - $patches = PhabricatorSQLPatchList::getPatchList(); |
129 |
| - |
130 |
| - $patch_applied = false; |
131 |
| - foreach ($patches as $patch) { |
132 |
| - if ($patch['version'] < $next_version) { |
133 |
| - continue; |
134 |
| - } |
135 |
| - |
136 |
| - if ($max_version && $patch['version'] > $max_version) { |
137 |
| - continue; |
138 |
| - } |
139 |
| - |
140 |
| - $short_name = basename($patch['path']); |
141 |
| - print "Applying patch {$short_name}...\n"; |
142 |
| - |
143 |
| - if (!empty($options['d'])) { |
144 |
| - $patch_applied = true; |
145 |
| - continue; |
146 |
| - } |
147 |
| - |
148 |
| - if ($conn_port) { |
149 |
| - $port = '--port='.(int)$conn_port; |
150 |
| - } else { |
151 |
| - $port = null; |
152 |
| - } |
153 |
| - |
154 |
| - if (preg_match('/\.php$/', $patch['path'])) { |
155 |
| - $schema_conn = $conn; |
156 |
| - require_once $patch['path']; |
157 |
| - } else { |
158 |
| - list($stdout, $stderr) = execx( |
159 |
| - "mysql --user=%s --password=%s --host=%s {$port} ". |
160 |
| - "--default-character-set=utf8 < %s", |
161 |
| - $conn_user, |
162 |
| - $conn_pass, |
163 |
| - $conn_bare_hostname, |
164 |
| - $patch['path']); |
165 |
| - |
166 |
| - if ($stderr) { |
167 |
| - print $stderr; |
168 |
| - exit(-1); |
169 |
| - } |
170 |
| - } |
171 |
| - |
172 |
| - // Patch was successful, update the db with the latest applied patch version |
173 |
| - // 'DELETE' and 'INSERT' instead of update, because the table might be empty |
174 |
| - queryfx( |
175 |
| - $conn, |
176 |
| - 'DELETE FROM phabricator_meta_data.%T', |
177 |
| - SCHEMA_VERSION_TABLE_NAME); |
178 |
| - queryfx( |
179 |
| - $conn, |
180 |
| - 'INSERT INTO phabricator_meta_data.%T VALUES (%d)', |
181 |
| - SCHEMA_VERSION_TABLE_NAME, |
182 |
| - $patch['version']); |
183 |
| - |
184 |
| - $patch_applied = true; |
185 |
| - } |
186 |
| - |
187 |
| - if (!$patch_applied) { |
188 |
| - print "Your database is already up-to-date.\n"; |
189 |
| - } |
190 |
| - |
191 |
| -} catch (AphrontQueryAccessDeniedException $ex) { |
192 |
| - echo |
193 |
| - "ACCESS DENIED\n". |
194 |
| - "The user '{$conn_user}' does not have sufficient MySQL privileges to\n". |
195 |
| - "execute the schema upgrade. Use the -u and -p flags to run as a user\n". |
196 |
| - "with more privileges (e.g., root).". |
197 |
| - "\n\n". |
198 |
| - "EXCEPTION:\n". |
199 |
| - $ex->getMessage(). |
200 |
| - "\n\n"; |
201 |
| - exit(1); |
202 |
| -} |
203 |
| - |
204 |
| -function usage() { |
205 |
| - echo |
206 |
| - "usage: upgrade_schema.php [-v version] [-u user -p pass] [-f] [-h]". |
207 |
| - "\n\n". |
208 |
| - "Run 'upgrade_schema.php -u root -p hunter2' to override the configured ". |
209 |
| - "default user.\n". |
210 |
| - "Run 'upgrade_schema.php -v 12' to apply all patches starting from ". |
211 |
| - "version 12. It is very unlikely you need to do this.\n". |
212 |
| - "Run 'upgrade_schema.php -m 110' to apply all patches up to and ". |
213 |
| - "including version 110 (but nothing past).\n". |
214 |
| - "Use the -f flag to upgrade noninteractively, without prompting.\n". |
215 |
| - "Use the -d flag to do a dry run - patches that would be applied ". |
216 |
| - "will be listed, but not applied.\n". |
217 |
| - "Use the -h flag to show this help.\n"; |
218 |
| - exit(1); |
219 |
| -} |
220 |
| - |
| 20 | +echo "This script has been replaced by 'phabricator/bin/storage'.\n\n". |
| 21 | + "Run:\n\n". |
| 22 | + " phabricator/bin $ ./storage help\n\n". |
| 23 | + "...for help, or:\n\n". |
| 24 | + " phabricator/bin $ ./storage upgrade\n\n". |
| 25 | + "...to upgrade storage.\n\n"; |
| 26 | +exit(1); |
0 commit comments