2020-10-23 13:59:39 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
2022-01-10 14:05:01 +03:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2020-10-23 13:59:39 +03:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
|
|
|
final class Version20201023090929 extends AbstractMigration
|
|
|
|
{
|
|
|
|
private const IMPORT_SOURCE_COLUMN = 'import_source';
|
|
|
|
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$shortUrls = $schema->getTable('short_urls');
|
|
|
|
$this->skipIf($shortUrls->hasColumn(self::IMPORT_SOURCE_COLUMN));
|
|
|
|
|
|
|
|
$shortUrls->addColumn(self::IMPORT_SOURCE_COLUMN, Types::STRING, [
|
|
|
|
'length' => 255,
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
2020-10-25 13:57:26 +03:00
|
|
|
$shortUrls->addColumn('import_original_short_code', Types::STRING, [
|
|
|
|
'length' => 255,
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$shortUrls->addUniqueIndex(
|
|
|
|
[self::IMPORT_SOURCE_COLUMN, 'import_original_short_code', 'domain_id'],
|
|
|
|
'unique_imports',
|
|
|
|
);
|
2020-10-23 13:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$shortUrls = $schema->getTable('short_urls');
|
|
|
|
$this->skipIf(! $shortUrls->hasColumn(self::IMPORT_SOURCE_COLUMN));
|
|
|
|
|
|
|
|
$shortUrls->dropColumn(self::IMPORT_SOURCE_COLUMN);
|
2020-10-25 13:57:26 +03:00
|
|
|
$shortUrls->dropColumn('import_original_short_code');
|
|
|
|
$shortUrls->dropIndex('unique_imports');
|
2020-10-23 13:59:39 +03:00
|
|
|
}
|
2021-10-23 17:02:29 +03:00
|
|
|
|
|
|
|
public function isTransactional(): bool
|
|
|
|
{
|
2022-01-10 14:05:01 +03:00
|
|
|
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
|
2021-10-23 17:02:29 +03:00
|
|
|
}
|
2020-10-23 13:59:39 +03:00
|
|
|
}
|