2021-02-07 13:26:01 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
|
|
|
use Shlinkio\Shlink\Core\Model\Visitor;
|
|
|
|
|
|
|
|
final class Version20210207100807 extends AbstractMigration
|
|
|
|
{
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visits = $schema->getTable('visits');
|
2021-02-16 00:16:58 +03:00
|
|
|
$this->skipIf($visits->hasColumn('visited_url'));
|
2021-02-07 13:26:01 +03:00
|
|
|
|
2021-02-16 00:16:58 +03:00
|
|
|
$shortUrlId = $visits->getColumn('short_url_id');
|
2021-02-07 13:26:01 +03: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,
|
|
|
|
'default' => Visit::TYPE_VALID_SHORT_URL,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$visits = $schema->getTable('visits');
|
2021-02-16 00:16:58 +03:00
|
|
|
$this->skipIf(! $visits->hasColumn('visited_url'));
|
2021-02-07 13:26:01 +03:00
|
|
|
|
2021-02-16 00:16:58 +03:00
|
|
|
$shortUrlId = $visits->getColumn('short_url_id');
|
2021-02-07 13:26:01 +03:00
|
|
|
$shortUrlId->setNotnull(true);
|
|
|
|
$visits->dropColumn('visited_url');
|
|
|
|
$visits->dropColumn('type');
|
|
|
|
}
|
2021-10-23 17:02:29 +03:00
|
|
|
|
|
|
|
public function isTransactional(): bool
|
|
|
|
{
|
|
|
|
return $this->connection->getDatabasePlatform()->getName() !== 'mysql';
|
|
|
|
}
|
2021-02-07 13:26:01 +03:00
|
|
|
}
|