1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Script to selectively convert MyISAM tables to InnoDB

Summary:
A bunch of the .sql patch files don't explicitly specify the table engine, but
we should always use InnoDB with the exception of one table which needs MyISAM
for FULLTEXT.

MySQL doesn't no-op an ALTER TABLE statment that changes the engine back to
itself and converting large tables can be time consuming, so convert only the
required tables.

Test Plan: Ran on secure.phabricator.com and my local box, it fixed all the
issues in about 3 seconds on secure.phabricator.com and <<1 second on my local.
Reviewed By: codeblock
Reviewers: codeblock, tuomaspelkonen, jungejason, aran
CC: aran, epriestley, codeblock
Differential Revision: 641
This commit is contained in:
epriestley 2011-07-11 10:46:54 -07:00
parent 36e00db564
commit 467308dd12
3 changed files with 68 additions and 18 deletions

View file

@ -0,0 +1,47 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
$conn = $schema_conn;
$tables = queryfx_all(
$conn,
"SELECT TABLE_SCHEMA db, TABLE_NAME tbl
FROM information_schema.TABLES s
WHERE s.TABLE_SCHEMA LIKE %>
AND s.TABLE_NAME != 'search_documentfield'
AND s.ENGINE != 'InnoDB'",
'phabricator_');
if (!$tables) {
return;
}
echo "There are ".count($tables)." tables using the MyISAM engine. These will ".
"now be converted to InnoDB. This process may take a few minutes, please ".
"be patient.\n";
foreach ($tables as $table) {
$name = $table['db'].'.'.$table['tbl'];
echo "Converting {$name}...\n";
queryfx(
$conn,
"ALTER TABLE %T.%T ENGINE=InnoDB",
$table['db'],
$table['tbl']);
}
echo "Done!\n";

View file

@ -137,16 +137,21 @@ END;
$port = null;
}
list($stdout, $stderr) = execx(
"mysql --user=%s --password=%s --host=%s {$port} < %s",
$conn_user,
$conn_pass,
$conn_bare_hostname,
$patch['path']);
if (preg_match('/\.php$/', $patch['path'])) {
$schema_conn = $conn;
require_once $patch['path'];
} else {
list($stdout, $stderr) = execx(
"mysql --user=%s --password=%s --host=%s {$port} < %s",
$conn_user,
$conn_pass,
$conn_bare_hostname,
$patch['path']);
if ($stderr) {
print $stderr;
exit(-1);
if ($stderr) {
print $stderr;
exit(-1);
}
}
// Patch was successful, update the db with the latest applied patch version

View file

@ -23,21 +23,19 @@ final class PhabricatorSQLPatchList {
// Find the patch files
$patches_dir = $root.'/resources/sql/patches/';
$finder = id(new FileFinder($patches_dir))
->withSuffix('sql');
$finder = new FileFinder($patches_dir);
$results = $finder->find();
$patches = array();
foreach ($results as $path) {
$matches = array();
if (preg_match('/(\d+)\..*\.sql$/', $path, $matches)) {
$patches[] = array(
'version' => (int)$matches[1],
'path' => $patches_dir.$path,
);
} else {
throw new Exception("Patch file '{$path}' is not properly named.");
if (!preg_match('/(\d+)\..*\.(sql|php)$/', $path, $matches)) {
continue;
}
$patches[] = array(
'version' => (int)$matches[1],
'path' => $patches_dir.$path,
);
}
// Files are in some 'random' order returned by the operating system