mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* smart collection names must be case insensitive * use explicit ci collation for mysqlpull/2723/head
9 changed files with 13722 additions and 4 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,56 @@ |
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||||
|
|
||||||
|
#nullable disable |
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.MySql.Migrations |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Fix_SmartCollectionNameSensitivity : Migration |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.Sql( |
||||||
|
@"
|
||||||
|
WITH Numbered AS ( |
||||||
|
SELECT |
||||||
|
Id, |
||||||
|
ROW_NUMBER() OVER (PARTITION BY LOWER(Name) ORDER BY Id) as RowNum |
||||||
|
FROM SmartCollection |
||||||
|
) |
||||||
|
UPDATE SmartCollection sc |
||||||
|
JOIN Numbered n ON sc.Id = n.Id |
||||||
|
SET sc.Name = CONCAT(sc.Name, ' (', n.RowNum - 1, ')') |
||||||
|
WHERE n.RowNum > 1; |
||||||
|
");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>( |
||||||
|
name: "Name", |
||||||
|
table: "SmartCollection", |
||||||
|
type: "varchar(255)", |
||||||
|
nullable: true, |
||||||
|
collation: "utf8mb4_general_ci", |
||||||
|
oldClrType: typeof(string), |
||||||
|
oldType: "varchar(255)", |
||||||
|
oldNullable: true) |
||||||
|
.Annotation("MySql:CharSet", "utf8mb4") |
||||||
|
.OldAnnotation("MySql:CharSet", "utf8mb4"); |
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.AlterColumn<string>( |
||||||
|
name: "Name", |
||||||
|
table: "SmartCollection", |
||||||
|
type: "varchar(255)", |
||||||
|
nullable: true, |
||||||
|
oldClrType: typeof(string), |
||||||
|
oldType: "varchar(255)", |
||||||
|
oldNullable: true, |
||||||
|
oldCollation: "utf8mb4_general_ci") |
||||||
|
.Annotation("MySql:CharSet", "utf8mb4") |
||||||
|
.OldAnnotation("MySql:CharSet", "utf8mb4"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,53 @@ |
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||||
|
|
||||||
|
#nullable disable |
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.Sqlite.Migrations |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Fix_SmartCollectionNameSensitivity : Migration |
||||||
|
{ |
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.Sql(@"
|
||||||
|
WITH Numbered AS ( |
||||||
|
SELECT |
||||||
|
Id, |
||||||
|
-- Partition by case-insensitive name |
||||||
|
ROW_NUMBER() OVER (PARTITION BY Name COLLATE NOCASE ORDER BY Id) AS RowNum |
||||||
|
FROM SmartCollection |
||||||
|
) |
||||||
|
UPDATE SmartCollection |
||||||
|
SET Name = Name || ' (' || (Numbered.RowNum - 1) || ')' |
||||||
|
FROM Numbered |
||||||
|
WHERE SmartCollection.Id = Numbered.Id |
||||||
|
AND Numbered.RowNum > 1; |
||||||
|
");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>( |
||||||
|
name: "Name", |
||||||
|
table: "SmartCollection", |
||||||
|
type: "TEXT", |
||||||
|
nullable: true, |
||||||
|
collation: "NOCASE", |
||||||
|
oldClrType: typeof(string), |
||||||
|
oldType: "TEXT", |
||||||
|
oldNullable: true); |
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.AlterColumn<string>( |
||||||
|
name: "Name", |
||||||
|
table: "SmartCollection", |
||||||
|
type: "TEXT", |
||||||
|
nullable: true, |
||||||
|
oldClrType: typeof(string), |
||||||
|
oldType: "TEXT", |
||||||
|
oldNullable: true, |
||||||
|
oldCollation: "NOCASE"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue