mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-28 20:41:41 +03:00
Merge pull request #2019 from acelaya-forks/feature/long-url-as-text
Change long URL columns to TEXT type
This commit is contained in:
commit
0bacb215c5
5 changed files with 63 additions and 8 deletions
|
@ -25,7 +25,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
||||||
* [#1786](https://github.com/shlinkio/shlink/issues/1786) Run API tests with RoadRunner by default.
|
* [#1786](https://github.com/shlinkio/shlink/issues/1786) Run API tests with RoadRunner by default.
|
||||||
* [#2008](https://github.com/shlinkio/shlink/issues/2008) Update to Doctrine ORM 3.0.
|
* [#2008](https://github.com/shlinkio/shlink/issues/2008) Update to Doctrine ORM 3.0.
|
||||||
* [#2010](https://github.com/shlinkio/shlink/issues/2010) Update to Symfony 7.0 components.
|
* [#2010](https://github.com/shlinkio/shlink/issues/2010) Update to Symfony 7.0 components.
|
||||||
* [#2016](https://github.com/shlinkio/shlink/issues/2016) Simplify and improve how code coverage is generated in API and CLI tests".
|
* [#2016](https://github.com/shlinkio/shlink/issues/2016) Simplify and improve how code coverage is generated in API and CLI tests.
|
||||||
|
* [#1674](https://github.com/shlinkio/shlink/issues/1674) Database columns persisting long URLs have now `TEXT` type, which allows for much longer values.
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
* *Nothing*
|
* *Nothing*
|
||||||
|
|
|
@ -25,17 +25,17 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
->unique()
|
->unique()
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
fieldWithUtf8Charset($builder->createField('baseUrlRedirect', Types::STRING), $emConfig)
|
fieldWithUtf8Charset($builder->createField('baseUrlRedirect', Types::TEXT), $emConfig)
|
||||||
->columnName('base_url_redirect')
|
->columnName('base_url_redirect')
|
||||||
->nullable()
|
->nullable()
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
fieldWithUtf8Charset($builder->createField('regular404Redirect', Types::STRING), $emConfig)
|
fieldWithUtf8Charset($builder->createField('regular404Redirect', Types::TEXT), $emConfig)
|
||||||
->columnName('regular_not_found_redirect')
|
->columnName('regular_not_found_redirect')
|
||||||
->nullable()
|
->nullable()
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
fieldWithUtf8Charset($builder->createField('invalidShortUrlRedirect', Types::STRING), $emConfig)
|
fieldWithUtf8Charset($builder->createField('invalidShortUrlRedirect', Types::TEXT), $emConfig)
|
||||||
->columnName('invalid_short_url_redirect')
|
->columnName('invalid_short_url_redirect')
|
||||||
->nullable()
|
->nullable()
|
||||||
->build();
|
->build();
|
||||||
|
|
|
@ -30,9 +30,8 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
->length(255)
|
->length(255)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
fieldWithUtf8Charset($builder->createField('longUrl', Types::STRING), $emConfig)
|
fieldWithUtf8Charset($builder->createField('longUrl', Types::TEXT), $emConfig)
|
||||||
->columnName('long_url')
|
->columnName('long_url')
|
||||||
->length(2048)
|
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
$builder->createManyToOne('shortUrl', ShortUrl\Entity\ShortUrl::class)
|
$builder->createManyToOne('shortUrl', ShortUrl\Entity\ShortUrl::class)
|
||||||
|
|
|
@ -23,9 +23,8 @@ return static function (ClassMetadata $metadata, array $emConfig): void {
|
||||||
->option('unsigned', true)
|
->option('unsigned', true)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
fieldWithUtf8Charset($builder->createField('longUrl', Types::STRING), $emConfig)
|
fieldWithUtf8Charset($builder->createField('longUrl', Types::TEXT), $emConfig)
|
||||||
->columnName('original_url') // Rename to long_url some day? ¯\_(ツ)_/¯
|
->columnName('original_url') // Rename to long_url some day? ¯\_(ツ)_/¯
|
||||||
->length(2048)
|
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
fieldWithUtf8Charset($builder->createField('shortCode', Types::STRING), $emConfig, 'bin')
|
fieldWithUtf8Charset($builder->createField('shortCode', Types::STRING), $emConfig, 'bin')
|
||||||
|
|
56
module/Core/migrations/Version20240220214031.php
Normal file
56
module/Core/migrations/Version20240220214031.php
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\DBAL\Types\Type;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
use function in_array;
|
||||||
|
|
||||||
|
final class Version20240220214031 extends AbstractMigration
|
||||||
|
{
|
||||||
|
private const DOMAINS_COLUMNS = ['base_url_redirect', 'regular_not_found_redirect', 'invalid_short_url_redirect'];
|
||||||
|
private const TEXT_COLUMNS = [
|
||||||
|
'domains' => self::DOMAINS_COLUMNS,
|
||||||
|
'device_long_urls' => ['long_url'],
|
||||||
|
'short_urls' => ['original_url'],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$textType = Type::getType(Types::TEXT);
|
||||||
|
|
||||||
|
foreach (self::TEXT_COLUMNS as $table => $columns) {
|
||||||
|
$t = $schema->getTable($table);
|
||||||
|
|
||||||
|
foreach ($columns as $column) {
|
||||||
|
$c = $t->getColumn($column);
|
||||||
|
|
||||||
|
if ($c->getType() === $textType) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($column, self::DOMAINS_COLUMNS, true)) {
|
||||||
|
// Domain columns had an incorrect length
|
||||||
|
$t->modifyColumn($column, ['length' => 2048]);
|
||||||
|
}
|
||||||
|
$c->setType($textType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// Can't revert from TEXT to STRING, as it's bigger
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isTransactional(): bool
|
||||||
|
{
|
||||||
|
return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue