diff --git a/module/Core/migrations/Version20240220214031.php b/module/Core/migrations/Version20240220214031.php index b8dc12fd..adceb7f2 100644 --- a/module/Core/migrations/Version20240220214031.php +++ b/module/Core/migrations/Version20240220214031.php @@ -12,6 +12,9 @@ use Doctrine\Migrations\AbstractMigration; use function in_array; +/** + * Convert all columns containing long URLs to TEXT type + */ final class Version20240220214031 extends AbstractMigration { private const DOMAINS_COLUMNS = ['base_url_redirect', 'regular_not_found_redirect', 'invalid_short_url_redirect']; diff --git a/module/Core/migrations/Version20240224115725.php b/module/Core/migrations/Version20240224115725.php index 2b68174c..1e069d83 100644 --- a/module/Core/migrations/Version20240224115725.php +++ b/module/Core/migrations/Version20240224115725.php @@ -10,6 +10,9 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Types; use Doctrine\Migrations\AbstractMigration; +/** + * Create new tables needed for the dynamic rule-based redirections + */ final class Version20240224115725 extends AbstractMigration { public function up(Schema $schema): void diff --git a/module/Core/migrations/Version20240226214216.php b/module/Core/migrations/Version20240226214216.php index fadea110..d7352717 100644 --- a/module/Core/migrations/Version20240226214216.php +++ b/module/Core/migrations/Version20240226214216.php @@ -4,11 +4,12 @@ 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; +/** + * Migrate data from device_long_urls to short_url_redirect_rules + */ final class Version20240226214216 extends AbstractMigration { public function up(Schema $schema): void @@ -85,42 +86,4 @@ final class Version20240226214216 extends AbstractMigration $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); - } } diff --git a/module/Core/migrations/Version20240227080629.php b/module/Core/migrations/Version20240227080629.php new file mode 100644 index 00000000..ad41dc54 --- /dev/null +++ b/module/Core/migrations/Version20240227080629.php @@ -0,0 +1,54 @@ +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); + } +}