2019-09-30 20:15:14 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2019-09-30 20:15:14 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkMigrations;
|
|
|
|
|
2022-01-10 14:05:01 +03:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2019-09-30 20:15:14 +03:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Schema\SchemaException;
|
2020-01-07 01:08:14 +03:00
|
|
|
use Doctrine\DBAL\Types\Types;
|
2019-09-30 20:15:14 +03:00
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
|
|
|
|
final class Version20190930165521 extends AbstractMigration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws SchemaException
|
|
|
|
*/
|
|
|
|
public function up(Schema $schema): void
|
|
|
|
{
|
|
|
|
$shortUrls = $schema->getTable('short_urls');
|
|
|
|
if ($shortUrls->hasColumn('domain_id')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$domains = $schema->createTable('domains');
|
2020-01-07 01:08:14 +03:00
|
|
|
$domains->addColumn('id', Types::BIGINT, [
|
2019-09-30 20:15:14 +03:00
|
|
|
'unsigned' => true,
|
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
2020-01-07 01:08:14 +03:00
|
|
|
$domains->addColumn('authority', Types::STRING, [
|
2019-09-30 20:15:14 +03:00
|
|
|
'length' => 512,
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
|
|
|
$domains->addUniqueIndex(['authority']);
|
|
|
|
$domains->setPrimaryKey(['id']);
|
|
|
|
|
2020-01-07 01:08:14 +03:00
|
|
|
$shortUrls->addColumn('domain_id', Types::BIGINT, [
|
2019-09-30 20:15:14 +03:00
|
|
|
'unsigned' => true,
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
|
|
|
$shortUrls->addForeignKeyConstraint('domains', ['domain_id'], ['id'], [
|
|
|
|
'onDelete' => 'RESTRICT',
|
|
|
|
'onUpdate' => 'RESTRICT',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws SchemaException
|
|
|
|
*/
|
|
|
|
public function down(Schema $schema): void
|
|
|
|
{
|
|
|
|
$schema->getTable('short_urls')->dropColumn('domain_id');
|
|
|
|
$schema->dropTable('domains');
|
|
|
|
}
|
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
|
|
|
}
|
2019-09-30 20:15:14 +03:00
|
|
|
}
|