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/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; - } -} 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'], ];