From 1ae2ce9e011fad924b33c6d290c9e7758dc80884 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 10 Jun 2026 12:06:39 +0200 Subject: [PATCH] Initialize long URL hash to empty string so that it's not necessary to set it as non-nullable afterwards --- docker-compose.yml | 2 +- module/CLI/src/Util/ProcessRunner.php | 8 +++--- .../Core/migrations/Version20260524105410.php | 2 +- .../Core/migrations/Version20260607082210.php | 10 ++++--- .../Core/migrations/Version20260609093926.php | 26 ------------------- 5 files changed, 13 insertions(+), 35 deletions(-) delete mode 100644 module/Core/migrations/Version20260609093926.php diff --git a/docker-compose.yml b/docker-compose.yml index 847c257e..4a569e4c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -127,7 +127,7 @@ services: shlink_db_maria: container_name: shlink_db_maria user: 1000:1000 - image: mariadb:10.7 + image: mariadb:12.3 ports: - "3308:3306" volumes: diff --git a/module/CLI/src/Util/ProcessRunner.php b/module/CLI/src/Util/ProcessRunner.php index 2c501314..a27efa60 100644 --- a/module/CLI/src/Util/ProcessRunner.php +++ b/module/CLI/src/Util/ProcessRunner.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Util; use Closure; -use Shlinkio\Shlink\CLI\Command\Util\LockConfig; use Symfony\Component\Console\Helper\DebugFormatterHelper; use Symfony\Component\Console\Helper\ProcessHelper; use Symfony\Component\Console\Output\ConsoleOutputInterface; @@ -18,13 +17,15 @@ use function str_replace; class ProcessRunner implements ProcessRunnerInterface { + private const int TIMEOUT = 1_200; // 20 minutes + private Closure $createProcess; - public function __construct(private ProcessHelper $helper, callable|null $createProcess = null) + public function __construct(private readonly ProcessHelper $helper, callable|null $createProcess = null) { $this->createProcess = $createProcess !== null ? $createProcess(...) - : static fn (array $cmd) => new Process($cmd, timeout: LockConfig::DEFAULT_TTL); + : static fn (array $cmd) => new Process($cmd, timeout: self::TIMEOUT); } public function run(OutputInterface $output, array $cmd): void @@ -35,7 +36,6 @@ class ProcessRunner implements ProcessRunnerInterface /** @var DebugFormatterHelper $formatter */ $formatter = $this->helper->getHelperSet()?->get('debug_formatter') ?? new DebugFormatterHelper(); - /** @var Process $process */ $process = ($this->createProcess)($cmd); if ($output->isVeryVerbose()) { diff --git a/module/Core/migrations/Version20260524105410.php b/module/Core/migrations/Version20260524105410.php index ae9d8edc..74db0cbc 100644 --- a/module/Core/migrations/Version20260524105410.php +++ b/module/Core/migrations/Version20260524105410.php @@ -26,7 +26,7 @@ final class Version20260524105410 extends AbstractMigration $shortUrls->addColumn(self::COLUMN_NAME, Types::BINARY, [ 'length' => 32, - 'notnull' => false, // Temporarily nullable until values have been filled + 'default' => '', // Temporary value until they have been filled by next migration ]); $shortUrls->addIndex([self::COLUMN_NAME], self::INDEX_NAME); } diff --git a/module/Core/migrations/Version20260607082210.php b/module/Core/migrations/Version20260607082210.php index 3665076d..be64ade6 100644 --- a/module/Core/migrations/Version20260607082210.php +++ b/module/Core/migrations/Version20260607082210.php @@ -20,15 +20,19 @@ final class Version20260607082210 extends AbstractMigration $qb = $this->connection->createQueryBuilder(); $qb ->select('id', 'original_url') - ->from('short_urls'); + ->from('short_urls') + // If this migration times out, this will ensure it can be rerun, and it will continue where it was left, so + // it can be run multiple times until all short URLs have been processed + ->where($qb->expr()->eq('long_url_hash', ':longUrlHash')) + ->setParameters(['longUrlHash' => '']); $shortUrlsResult = $qb->executeQuery(); - $iteration = 0; + $iteration = 1; $this->connection->beginTransaction(); while ($row = $shortUrlsResult->fetchAssociative()) { // Every few updates, commit the transaction and begin a new one - if (($iteration % 2000) === 0) { + if (($iteration % 10_000) === 0) { $this->connection->commit(); $this->connection->beginTransaction(); } diff --git a/module/Core/migrations/Version20260609093926.php b/module/Core/migrations/Version20260609093926.php deleted file mode 100644 index 9935661d..00000000 --- a/module/Core/migrations/Version20260609093926.php +++ /dev/null @@ -1,26 +0,0 @@ -getTable('short_urls'); - $shortUrls->getColumn('long_url_hash')->setNotnull(true); - } - - public function isTransactional(): bool - { - return !$this->connection->getDatabasePlatform() instanceof MySQLPlatform; - } -}