Skip to content

Commit

Permalink
Prefer addSql() over executeStatement() in migrations
Browse files Browse the repository at this point in the history
executeStatement() doesn't work well in migrations; for example it
doesn't respect the --dry-run option.

In Version20210407120356.php it's not possible to use addSql(),
because the statements use the results of previous statements. This
commit changes that file to use *only* executeStatement() for
consistency.

Also remove an unused import.
  • Loading branch information
tom93 committed Jul 30, 2024
1 parent 4f87cbd commit 8dc62bd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion webapp/migrations/Version20210407120356.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function up(Schema $schema) : void
);
}

$this->addSql('ALTER TABLE `executable` DROP COLUMN `zipfile`');
$this->connection->executeStatement('ALTER TABLE `executable` DROP COLUMN `zipfile`');
}
}

Expand Down
3 changes: 1 addition & 2 deletions webapp/migrations/Version20230508163415.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace DoctrineMigrations;

use App\Entity\ExecutableFile;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

Expand Down Expand Up @@ -32,7 +31,7 @@ public function up(Schema $schema): void
)
)
);
$this->connection->executeQuery('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [
$this->addSql('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [
'hash' => $newHash,
'id' => $immutableExecutable['immutable_execid'],
]);
Expand Down
2 changes: 1 addition & 1 deletion webapp/migrations/Version20231120225210.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function up(Schema $schema): void

if ($updated) {
$newExtensionsJson = json_encode($extensions);
$this->connection->executeQuery('UPDATE language SET extensions = :extensions WHERE langid = :langid', [
$this->addSql('UPDATE language SET extensions = :extensions WHERE langid = :langid', [
'extensions' => $newExtensionsJson,
'langid' => $language['langid'],
]);
Expand Down

0 comments on commit 8dc62bd

Please sign in to comment.