ModifyTableField("buildupdate", "id", "int(11)", "bigint", "", true, true); RenameTableField("updatefile", "buildid", "updateid", "int(11)", "bigint", "0"); AddTableField('site', 'outoforder', 'tinyint(1)', 'smallint', '0'); // Set the database version setVersion(); // Put that the upgrade is done in the log add_log("Upgrade done.", "upgrade-2-2"); return; } // 2.4 Upgrade if (isset($_GET['upgrade-2-4'])) { // Support for subproject groups AddTableField('subproject', 'groupid', 'int(11)', 'bigint', '0'); AddTableIndex('subproject', 'groupid'); RemoveTableField("subproject", "core"); RemoveTableField('project', 'coveragethreshold2'); // Support for larger types ModifyTableField("buildfailure", "workingdirectory", "VARCHAR( 512)", "VARCHAR( 512 )", "", true, false); ModifyTableField("buildfailure", "outputfile", "VARCHAR( 512)", "VARCHAR( 512 )", "", true, false); // Support for parent builds AddTableField('build', 'parentid', 'int(11)', 'int', '0'); AddTableIndex('build', 'parentid'); // Cache configure results similar to build & test AddTableField('build', 'configureerrors', 'smallint(6)', 'smallint', '-1'); AddTableField('build', 'configurewarnings', 'smallint(6)', 'smallint', '-1'); // Add new multi-column index to build table. // This improves the rendering speed of overview.php. $multi_index = array("projectid", "parentid", "starttime"); AddTableIndex("build", $multi_index); // Support for dynamic BuildGroups. AddTableField('buildgroup', 'type', 'varchar(20)', 'character varying(20)', 'Daily');
/** Move some columns from buildfailure to buildfailuredetails table. * This function is parameterized to make it easier to test. **/ function UpgradeBuildFailureTable($from_table = 'buildfailure', $to_table = 'buildfailuredetails') { // Check if the buildfailure table has a column named 'stdout'. If not, // we should return early because this upgrade has already been performed. $result = pdo_query("SELECT column_name FROM information_schema.columns\n WHERE table_name='{$from_table}' and column_name='stdoutput'"); if (pdo_num_rows($result) == 0) { return; } // Add the detailsid field to our buildfailure table. AddTableField($from_table, 'detailsid', 'bigint(20)', 'bigserial', '0'); // Iterate over buildfailure rows. // We break this up into separate queries of 5,000 each because otherwise // memory usage increases with each iteration of our loop. $count_results = pdo_single_row_query("SELECT COUNT(1) AS numfails FROM {$from_table}"); $numfails = intval($count_results['numfails']); $numconverted = 0; $last_id = 0; $stride = 5000; while ($numconverted < $numfails) { $result = pdo_query("SELECT * FROM {$from_table} WHERE id > {$last_id} ORDER BY id LIMIT {$stride}"); while ($row = pdo_fetch_array($result)) { // Compute crc32 for this buildfailure's details. $crc32 = crc32($row['outputfile'] . $row['stdoutput'] . $row['stderror'] . $row['sourcefile']); // Get detailsid if it already exists, otherwise insert a new row. $details_result = pdo_single_row_query("SELECT id FROM {$to_table} WHERE crc32=" . qnum($crc32)); if ($details_result && array_key_exists('id', $details_result)) { $details_id = $details_result['id']; } else { $type = $row['type']; $stdoutput = pdo_real_escape_string($row['stdoutput']); $stderror = pdo_real_escape_string($row['stderror']); $exitcondition = pdo_real_escape_string($row['exitcondition']); $language = pdo_real_escape_string($row['language']); $targetname = pdo_real_escape_string($row['targetname']); $outputfile = pdo_real_escape_string($row['outputfile']); $outputtype = pdo_real_escape_string($row['outputtype']); $query = "INSERT INTO {$to_table}\n (type, stdoutput, stderror, exitcondition, language, targetname,\n outputfile, outputtype, crc32)\n VALUES\n ('{$type}', '{$stdoutput}', '{$stderror}', '{$exitcondition}', '{$language}',\n '{$targetname}', '{$outputfile}', '{$outputtype}','{$crc32}')"; if (!pdo_query($query)) { add_last_sql_error("UpgradeBuildFailureTable::InsertDetails", 0, $row['id']); } $details_id = pdo_insert_id($to_table); } $query = "UPDATE {$from_table} SET detailsid=" . qnum($details_id) . "\n WHERE id=" . qnum($row['id']); if (!pdo_query($query)) { add_last_sql_error("UpgradeBuildFailureTable::UpdateDetailsId", 0, $details_id); } $last_id = $row['id']; } $numconverted += $stride; } // Remove old columns from buildfailure table. RemoveTableField($from_table, 'type'); RemoveTableField($from_table, 'stdoutput'); RemoveTableField($from_table, 'stderror'); RemoveTableField($from_table, 'exitcondition'); RemoveTableField($from_table, 'language'); RemoveTableField($from_table, 'targetname'); RemoveTableField($from_table, 'outputfile'); RemoveTableField($from_table, 'outputtype'); RemoveTableField($from_table, 'crc32'); }