1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 17:30:59 +01:00

Fix 20130820.file-mailkey-populate.php for databases in strict mode

Summary:
Fixes T3803. Turns out my advice was sort of terrible. :/

In strict mode, the `INSERT INTO x (y, z)` raises an error unless `(y, z, ...)` includes //all// columns without default values.

Test Plan: Ran `storage upgrade` on a strict-mode install. Verified no inserts were performed.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3803

Differential Revision: https://secure.phabricator.com/D6894
This commit is contained in:
epriestley 2013-09-05 15:58:28 -07:00
parent 228496cdbe
commit 2d240142c8

View file

@ -10,9 +10,13 @@ $conn_w->openTransaction();
$sql = array(); $sql = array();
foreach (new LiskRawMigrationIterator($conn_w, 'file') as $row) { foreach (new LiskRawMigrationIterator($conn_w, 'file') as $row) {
// NOTE: MySQL requires that the INSERT specify all columns which don't
// have default values when configured in strict mode. This query will
// never actually insert rows, but we need to hand it values anyway.
$sql[] = qsprintf( $sql[] = qsprintf(
$conn_w, $conn_w,
'(%d, %s)', '(%d, %s, 0, 0, 0, 0, 0, 0, 0, 0)',
$row['id'], $row['id'],
Filesystem::readRandomCharacters(20)); Filesystem::readRandomCharacters(20));
} }
@ -21,7 +25,9 @@ if ($sql) {
foreach (PhabricatorLiskDAO::chunkSQL($sql, ', ') as $chunk) { foreach (PhabricatorLiskDAO::chunkSQL($sql, ', ') as $chunk) {
queryfx( queryfx(
$conn_w, $conn_w,
'INSERT INTO %T (id, mailKey) VALUES %Q '. 'INSERT INTO %T
(id, mailKey, phid, byteSize, storageEngine, storageFormat,
storageHandle, dateCreated, dateModified, metadata) VALUES %Q '.
'ON DUPLICATE KEY UPDATE mailKey = VALUES(mailKey)', 'ON DUPLICATE KEY UPDATE mailKey = VALUES(mailKey)',
$table_name, $table_name,
$chunk); $chunk);