Adds index on the valid_until column of the short_urls table to improve the performance of the DeleteExpiredShortUrlsCommand

This commit is contained in:
Marijn Vandevoorde 2024-04-25 22:13:46 +02:00
parent 59fa088975
commit 814c9f06d9

View File

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace ShlinkMigrations;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20240425194703 extends AbstractMigration
{
private const INDEX_NAME = 'IDX_links_expiry_date';
public function up(Schema $schema): void
{
$visits = $schema->getTable('short_urls');
$this->skipIf($visits->hasIndex(self::INDEX_NAME));
$visits->addIndex(['valid_until'], self::INDEX_NAME);
}
public function down(Schema $schema): void
{
$visits = $schema->getTable('short_urls');
$this->skipIf(!$visits->hasIndex(self::INDEX_NAME));
$visits->dropIndex(self::INDEX_NAME);
}
public function isTransactional(): bool
{
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
}
}