Skip to content

Commit

Permalink
Use query parameters in migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tom93 committed Jul 31, 2024
1 parent b02a39b commit 8687d5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
13 changes: 5 additions & 8 deletions webapp/migrations/Version20210407120356.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function up(Schema $schema) : void
for ($idx = 0; $idx < $zip->numFiles; $idx++) {
$filename = basename($zip->getNameIndex($idx));
$content = $zip->getFromIndex($idx);
$encodedContent = ($content === '' ? '' : ('0x' . strtoupper(bin2hex($content))));

// In doubt make files executable, but try to read it from the zip file.
$executableBit = '1';
Expand All @@ -52,17 +51,15 @@ public function up(Schema $schema) : void
$executableBit = '0';
}
$this->connection->executeStatement(
'INSERT INTO executable_file '
. '(`immutable_execid`, `filename`, `ranknumber`, `file_content`, `hash`, `is_executable`) '
. 'VALUES (' . $immutable_execid . ', "' . $filename . '", '
. $idx . ', ' . $encodedContent . ', "' . md5($content) . '", '
. $executableBit . ')'
'INSERT INTO executable_file (`immutable_execid`, `filename`, `ranknumber`, `file_content`, `hash`, `is_executable`)'
. ' VALUES (?, ?, ?, ?, ?, ?)',
[$immutable_execid, $filename, $idx, $content, md5($content), $executableBit]
);
}

$this->connection->executeStatement(
'UPDATE executable SET immutable_execid = '
. $immutable_execid . ' WHERE execid = "' . $oldRow['execid'] . '"'
'UPDATE executable SET immutable_execid = :immutable_execid WHERE execid = :execid',
['immutable_execid' => $immutable_execid, 'execid' => $oldRow['execid']]
);
}

Expand Down
28 changes: 20 additions & 8 deletions webapp/migrations/Version20240511091916.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,33 @@ public function getDescription(): string

public function up(Schema $schema): void
{
foreach (self::COMPILER_VERSION_COMMAND as $lang => $versionCommand) {
$this->addSql("UPDATE language SET compiler_version_command = '" . $versionCommand ."' WHERE langid='" . $lang . "' AND compiler_version_command IS NULL;");
foreach (self::COMPILER_VERSION_COMMAND as $langid => $versionCommand) {
$this->addSql(
"UPDATE language SET compiler_version_command = :compiler_version_command WHERE langid = :langid AND compiler_version_command IS NULL",
['compiler_version_command' => $versionCommand, 'langid' => $langid]
);
}
foreach (self::RUNNER_VERSION_COMMAND as $lang => $versionCommand) {
$this->addSql("UPDATE language SET runner_version_command = '" . $versionCommand ."' WHERE langid='" . $lang . "' AND runner_version_command IS NULL;");
foreach (self::RUNNER_VERSION_COMMAND as $langid => $versionCommand) {
$this->addSql(
"UPDATE language SET runner_version_command = :compiler_version_command WHERE langid = :langid AND runner_version_command IS NULL",
['compiler_version_command' => $versionCommand, 'langid' => $langid]
);
}
}

public function down(Schema $schema): void
{
foreach (self::COMPILER_VERSION_COMMAND as $lang => $versionCommand) {
$this->addSql("UPDATE language SET compiler_version_command = NULL WHERE langid='" . $lang . "' AND compiler_version_command = '" . $versionCommand ."';");
foreach (self::COMPILER_VERSION_COMMAND as $langid => $versionCommand) {
$this->addSql(
"UPDATE language SET compiler_version_command = NULL WHERE langid = :langid AND compiler_version_command = :compiler_version_command",
['compiler_version_command' => $versionCommand, 'langid' => $langid]
);
}
foreach (self::RUNNER_VERSION_COMMAND as $lang => $versionCommand) {
$this->addSql("UPDATE language SET runner_version_command = NULL WHERE langid='" . $lang . "' AND runner_version_command = '" . $versionCommand ."';");
foreach (self::RUNNER_VERSION_COMMAND as $langid => $versionCommand) {
$this->addSql(
"UPDATE language SET runner_version_command = NULL WHERE langid = :langid AND runner_version_command = :compiler_version_command",
['compiler_version_command' => $versionCommand, 'langid' => $langid]
);
}
}

Expand Down

0 comments on commit 8687d5c

Please sign in to comment.