From bb72c96ebb9a8b56530315b678d4bc8c41d55346 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 26 Nov 2024 10:17:28 +0100 Subject: [PATCH 1/2] Delete some old migrations --- .../Core/migrations/Version20220110113313.php | 73 ------------------- .../Core/migrations/Version20230103105343.php | 53 -------------- .../Core/migrations/Version20230130090946.php | 50 ------------- 3 files changed, 176 deletions(-) delete mode 100644 module/Core/migrations/Version20220110113313.php delete mode 100644 module/Core/migrations/Version20230103105343.php delete mode 100644 module/Core/migrations/Version20230130090946.php diff --git a/module/Core/migrations/Version20220110113313.php b/module/Core/migrations/Version20220110113313.php deleted file mode 100644 index 2b2fb4ea..00000000 --- a/module/Core/migrations/Version20220110113313.php +++ /dev/null @@ -1,73 +0,0 @@ - [ - 'original_url' => 'unicode_ci', - 'short_code' => 'bin', - 'import_original_short_code' => 'unicode_ci', - 'title' => 'unicode_ci', - ], - 'domains' => [ - 'authority' => 'unicode_ci', - 'base_url_redirect' => 'unicode_ci', - 'regular_not_found_redirect' => 'unicode_ci', - 'invalid_short_url_redirect' => 'unicode_ci', - ], - 'tags' => [ - 'name' => 'unicode_ci', - ], - 'visits' => [ - 'referer' => 'unicode_ci', - 'user_agent' => 'unicode_ci', - 'visited_url' => 'unicode_ci', - ], - 'visit_locations' => [ - 'country_code' => 'unicode_ci', - 'country_name' => 'unicode_ci', - 'region_name' => 'unicode_ci', - 'city_name' => 'unicode_ci', - 'timezone' => 'unicode_ci', - ], - ]; - - public function up(Schema $schema): void - { - $this->skipIf(! $this->isMySql(), 'This only sets MySQL-specific database options'); - - foreach (self::COLLATIONS as $tableName => $columns) { - $table = $schema->getTable($tableName); - - foreach ($columns as $columnName => $collation) { - $table->getColumn($columnName) - ->setPlatformOption('charset', self::CHARSET) - ->setPlatformOption('collation', self::CHARSET . '_' . $collation); - } - } - } - - public function down(Schema $schema): void - { - // No down - } - - public function isTransactional(): bool - { - return ! $this->isMySql(); - } - - private function isMySql(): bool - { - return $this->connection->getDatabasePlatform() instanceof MySQLPlatform; - } -} diff --git a/module/Core/migrations/Version20230103105343.php b/module/Core/migrations/Version20230103105343.php deleted file mode 100644 index c61a8a94..00000000 --- a/module/Core/migrations/Version20230103105343.php +++ /dev/null @@ -1,53 +0,0 @@ -skipIf($schema->hasTable(self::TABLE_NAME)); - - $table = $schema->createTable(self::TABLE_NAME); - $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::STRING, ['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 down(Schema $schema): void - { - $this->skipIf(! $schema->hasTable(self::TABLE_NAME)); - $schema->dropTable(self::TABLE_NAME); - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } -} diff --git a/module/Core/migrations/Version20230130090946.php b/module/Core/migrations/Version20230130090946.php deleted file mode 100644 index 49e6d9bb..00000000 --- a/module/Core/migrations/Version20230130090946.php +++ /dev/null @@ -1,50 +0,0 @@ -skipIf(! $this->isMsSql(), 'This only sets MsSQL-specific database options'); - - $shortUrls = $schema->getTable('short_urls'); - $shortCode = $shortUrls->getColumn('short_code'); - // Drop the unique index before changing the collation, as the field is part of this index - $shortUrls->dropIndex('unique_short_code_plus_domain'); - $shortCode->setPlatformOption('collation', 'Latin1_General_CS_AS'); - } - - public function postUp(Schema $schema): void - { - if ($this->isMsSql()) { - // The index needs to be re-created in postUp, but here, we can only use statements run against the - // connection directly - $this->connection->executeStatement( - 'CREATE INDEX unique_short_code_plus_domain ON short_urls (domain_id, short_code);', - ); - } - } - - public function down(Schema $schema): void - { - // No down - } - - public function isTransactional(): bool - { - return ! ($this->connection->getDatabasePlatform() instanceof MySQLPlatform); - } - - private function isMsSql(): bool - { - return $this->connection->getDatabasePlatform() instanceof SQLServerPlatform; - } -} From 8499087a3bc8040c1ad91a8bfa91ad8113f3ae68 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 28 Nov 2024 08:53:19 +0100 Subject: [PATCH 2/2] Move DEFAULT_DOMAIN constant to domains module --- .../Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php | 10 +++++++--- module/Core/migrations/Version20240220214031.php | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php b/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php index 2277b0e5..6edd89e5 100644 --- a/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php +++ b/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php @@ -28,10 +28,14 @@ return static function (ClassMetadata $metadata, array $emConfig): void { ->length(2048) ->build(); - fieldWithUtf8Charset($builder->createField('shortCode', Types::STRING), $emConfig, 'bin') + $shortCodeField = fieldWithUtf8Charset($builder->createField('shortCode', Types::STRING), $emConfig, 'bin') ->columnName('short_code') - ->length(255) - ->build(); + ->length(255); + if (($emConfig['connection']['driver'] ?? null) === 'pdo_sqlsrv') { + // Make sure a case-sensitive charset is set in short code for Microsoft SQL Server + $shortCodeField->option('collation', 'Latin1_General_CS_AS'); + } + $shortCodeField->build(); $builder->createField('dateCreated', ChronosDateTimeType::CHRONOS_DATETIME) ->columnName('date_created') diff --git a/module/Core/migrations/Version20240220214031.php b/module/Core/migrations/Version20240220214031.php index adceb7f2..3af587ef 100644 --- a/module/Core/migrations/Version20240220214031.php +++ b/module/Core/migrations/Version20240220214031.php @@ -20,7 +20,6 @@ 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'], ];