2024-02-20 15:57:33 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
2024-02-22 02:35:14 -06:00
|
|
|
use Doctrine\DBAL\Types\Type;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
2024-02-20 15:57:33 -06:00
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
2024-02-22 02:35:14 -06:00
|
|
|
use function in_array;
|
|
|
|
|
2024-02-20 15:57:33 -06:00
|
|
|
final class Version20240220214031 extends AbstractMigration
|
|
|
|
{
|
2024-02-22 02:35:14 -06:00
|
|
|
private const DOMAINS_COLUMNS = ['base_url_redirect', 'regular_not_found_redirect', 'invalid_short_url_redirect'];
|
|
|
|
private const TEXT_COLUMNS = [
|
|
|
|
'domains' => self::DOMAINS_COLUMNS,
|
|
|
|
'device_long_urls' => ['long_url'],
|
|
|
|
'short_urls' => ['original_url'],
|
|
|
|
];
|
|
|
|
|
2024-02-20 15:57:33 -06:00
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
2024-02-22 02:35:14 -06:00
|
|
|
$textType = Type::getType(Types::TEXT);
|
|
|
|
|
|
|
|
foreach (self::TEXT_COLUMNS as $table => $columns) {
|
|
|
|
$t = $schema->getTable($table);
|
2024-02-20 15:57:33 -06:00
|
|
|
|
2024-02-22 02:35:14 -06:00
|
|
|
foreach ($columns as $column) {
|
|
|
|
$c = $t->getColumn($column);
|
|
|
|
|
|
|
|
if ($c->getType() === $textType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($column, self::DOMAINS_COLUMNS, true)) {
|
|
|
|
// Domain columns had an incorrect length
|
|
|
|
$t->modifyColumn($column, ['length' => 2048]);
|
|
|
|
}
|
|
|
|
$c->setType($textType);
|
|
|
|
}
|
|
|
|
}
|
2024-02-20 15:57:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
2024-02-22 02:35:14 -06:00
|
|
|
// Can't revert from TEXT to STRING, as it's bigger
|
2024-02-20 15:57:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isTransactional(): bool
|
|
|
|
{
|
|
|
|
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
|
|
|
|
}
|
|
|
|
}
|