mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-27 16:26:37 +03:00
Create new migration to drop old device_long_urls table
This commit is contained in:
parent
73864b923d
commit
4ad3dc0bc7
4 changed files with 63 additions and 40 deletions
|
@ -12,6 +12,9 @@ use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
use function in_array;
|
use function in_array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert all columns containing long URLs to TEXT type
|
||||||
|
*/
|
||||||
final class Version20240220214031 extends AbstractMigration
|
final class Version20240220214031 extends AbstractMigration
|
||||||
{
|
{
|
||||||
private const DOMAINS_COLUMNS = ['base_url_redirect', 'regular_not_found_redirect', 'invalid_short_url_redirect'];
|
private const DOMAINS_COLUMNS = ['base_url_redirect', 'regular_not_found_redirect', 'invalid_short_url_redirect'];
|
||||||
|
|
|
@ -10,6 +10,9 @@ use Doctrine\DBAL\Schema\Table;
|
||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\Migrations\AbstractMigration;
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new tables needed for the dynamic rule-based redirections
|
||||||
|
*/
|
||||||
final class Version20240224115725 extends AbstractMigration
|
final class Version20240224115725 extends AbstractMigration
|
||||||
{
|
{
|
||||||
public function up(Schema $schema): void
|
public function up(Schema $schema): void
|
||||||
|
|
|
@ -4,11 +4,12 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace ShlinkMigrations;
|
namespace ShlinkMigrations;
|
||||||
|
|
||||||
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
use Doctrine\DBAL\Types\Types;
|
|
||||||
use Doctrine\Migrations\AbstractMigration;
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migrate data from device_long_urls to short_url_redirect_rules
|
||||||
|
*/
|
||||||
final class Version20240226214216 extends AbstractMigration
|
final class Version20240226214216 extends AbstractMigration
|
||||||
{
|
{
|
||||||
public function up(Schema $schema): void
|
public function up(Schema $schema): void
|
||||||
|
@ -85,42 +86,4 @@ final class Version20240226214216 extends AbstractMigration
|
||||||
$priorities[$shortUrlId] = $priority + 1;
|
$priorities[$shortUrlId] = $priority + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postUp(Schema $schema): void
|
|
||||||
{
|
|
||||||
$this->skipIf(! $schema->hasTable('device_long_urls'));
|
|
||||||
$schema->dropTable('device_long_urls');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(Schema $schema): void
|
|
||||||
{
|
|
||||||
$this->skipIf($schema->hasTable('device_long_urls'));
|
|
||||||
|
|
||||||
$table = $schema->createTable('device_long_urls');
|
|
||||||
$table->addColumn('id', Types::BIGINT, [
|
|
||||||
'unsigned' => true,
|
|
||||||
'autoincrement' => true,
|
|
||||||
'notnull' => true,
|
|
||||||
]);
|
|
||||||
$table->setPrimaryKey(['id']);
|
|
||||||
|
|
||||||
$table->addColumn('device_type', Types::STRING, ['length' => 255]);
|
|
||||||
$table->addColumn('long_url', Types::TEXT, ['length' => 2048]);
|
|
||||||
$table->addColumn('short_url_id', Types::BIGINT, [
|
|
||||||
'unsigned' => true,
|
|
||||||
'notnull' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$table->addForeignKeyConstraint('short_urls', ['short_url_id'], ['id'], [
|
|
||||||
'onDelete' => 'CASCADE',
|
|
||||||
'onUpdate' => 'RESTRICT',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$table->addUniqueIndex(['device_type', 'short_url_id'], 'UQ_device_type_per_short_url');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isTransactional(): bool
|
|
||||||
{
|
|
||||||
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
54
module/Core/migrations/Version20240227080629.php
Normal file
54
module/Core/migrations/Version20240227080629.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop device_long_urls table
|
||||||
|
*/
|
||||||
|
final class Version20240227080629 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->skipIf(! $schema->hasTable('device_long_urls'));
|
||||||
|
$schema->dropTable('device_long_urls');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->skipIf($schema->hasTable('device_long_urls'));
|
||||||
|
|
||||||
|
$table = $schema->createTable('device_long_urls');
|
||||||
|
$table->addColumn('id', Types::BIGINT, [
|
||||||
|
'unsigned' => true,
|
||||||
|
'autoincrement' => true,
|
||||||
|
'notnull' => true,
|
||||||
|
]);
|
||||||
|
$table->setPrimaryKey(['id']);
|
||||||
|
|
||||||
|
$table->addColumn('device_type', Types::STRING, ['length' => 255]);
|
||||||
|
$table->addColumn('long_url', Types::TEXT, ['length' => 2048]);
|
||||||
|
$table->addColumn('short_url_id', Types::BIGINT, [
|
||||||
|
'unsigned' => true,
|
||||||
|
'notnull' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$table->addForeignKeyConstraint('short_urls', ['short_url_id'], ['id'], [
|
||||||
|
'onDelete' => 'CASCADE',
|
||||||
|
'onUpdate' => 'RESTRICT',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$table->addUniqueIndex(['device_type', 'short_url_id'], 'UQ_device_type_per_short_url');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isTransactional(): bool
|
||||||
|
{
|
||||||
|
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue