2021-02-07 04:26:01 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
2022-01-10 05:05:01 -06:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2021-02-07 04:26:01 -06:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
2022-09-23 11:05:17 -05:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
2022-04-23 11:19:16 -05:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitType;
|
2021-02-07 04:26:01 -06:00
|
|
|
|
|
|
|
final class Version20210207100807 extends AbstractMigration
|
|
|
|
{
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visits = $schema->getTable('visits');
|
2021-02-15 15:16:58 -06:00
|
|
|
$this->skipIf($visits->hasColumn('visited_url'));
|
2021-02-07 04:26:01 -06:00
|
|
|
|
2021-02-15 15:16:58 -06:00
|
|
|
$shortUrlId = $visits->getColumn('short_url_id');
|
2021-02-07 04:26:01 -06:00
|
|
|
$shortUrlId->setNotnull(false);
|
|
|
|
|
|
|
|
$visits->addColumn('visited_url', Types::STRING, [
|
|
|
|
'length' => Visitor::VISITED_URL_MAX_LENGTH,
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
|
|
|
$visits->addColumn('type', Types::STRING, [
|
|
|
|
'length' => 255,
|
2022-04-23 11:19:16 -05:00
|
|
|
'default' => VisitType::VALID_SHORT_URL->value,
|
2021-02-07 04:26:01 -06:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visits = $schema->getTable('visits');
|
2021-02-15 15:16:58 -06:00
|
|
|
$this->skipIf(! $visits->hasColumn('visited_url'));
|
2021-02-07 04:26:01 -06:00
|
|
|
|
2021-02-15 15:16:58 -06:00
|
|
|
$shortUrlId = $visits->getColumn('short_url_id');
|
2021-02-07 04:26:01 -06:00
|
|
|
$shortUrlId->setNotnull(true);
|
|
|
|
$visits->dropColumn('visited_url');
|
|
|
|
$visits->dropColumn('type');
|
|
|
|
}
|
2021-10-23 09:02:29 -05:00
|
|
|
|
|
|
|
public function isTransactional(): bool
|
|
|
|
{
|
2022-01-10 05:05:01 -06:00
|
|
|
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
|
2021-10-23 09:02:29 -05:00
|
|
|
}
|
2021-02-07 04:26:01 -06:00
|
|
|
}
|