Browse Source

Database update. (#1334)

pull/1335/head
Sebastian Stehle 2 months ago
committed by GitHub
parent
commit
fd2b3c3bd3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      .github/workflows/dev.yml
  2. 7
      .github/workflows/release.yml
  3. 17
      backend/src/Squidex.Data.EntityFramework/AppDbContext.cs
  4. 1630
      backend/src/Squidex.Data.EntityFramework/Providers/MySql/App/Migrations/20260915181445_WidenOpenIddictTokenType.Designer.cs
  5. 63
      backend/src/Squidex.Data.EntityFramework/Providers/MySql/App/Migrations/20260915181445_WidenOpenIddictTokenType.cs
  6. 18
      backend/src/Squidex.Data.EntityFramework/Providers/MySql/App/Migrations/MySqlDbContextModelSnapshot.cs
  7. 1630
      backend/src/Squidex.Data.EntityFramework/Providers/Postgres/App/Migrations/20260915181452_WidenOpenIddictTokenType.Designer.cs
  8. 40
      backend/src/Squidex.Data.EntityFramework/Providers/Postgres/App/Migrations/20260915181452_WidenOpenIddictTokenType.cs
  9. 15
      backend/src/Squidex.Data.EntityFramework/Providers/Postgres/App/Migrations/PostgresDbContextModelSnapshot.cs
  10. 1632
      backend/src/Squidex.Data.EntityFramework/Providers/SqlServer/App/Migrations/20260915181458_WidenOpenIddictTokenType.Designer.cs
  11. 40
      backend/src/Squidex.Data.EntityFramework/Providers/SqlServer/App/Migrations/20260915181458_WidenOpenIddictTokenType.cs
  12. 15
      backend/src/Squidex.Data.EntityFramework/Providers/SqlServer/App/Migrations/SqlServerDbContextModelSnapshot.cs
  13. 39
      backend/tests/Squidex.Data.Tests/EntityFramework/Domain/Users/EFOpenIddictTests.cs

7
.github/workflows/dev.yml

@ -160,9 +160,10 @@ jobs:
- name: sqlserver
compose: docker-compose-sqlserver.yml
optional: false
- name: ferretdb
compose: docker-compose-ferretdb.yml
optional: true
# Disabled for now.
# - name: ferretdb
# compose: docker-compose-ferretdb.yml
# optional: true
continue-on-error: ${{ matrix.optional == true }}
steps:

7
.github/workflows/release.yml

@ -155,9 +155,10 @@ jobs:
- name: sqlserver
compose: docker-compose-sqlserver.yml
optional: false
- name: ferretdb
compose: docker-compose-ferretdb.yml
optional: true
# Disabled for now.
# - name: ferretdb
# compose: docker-compose-ferretdb.yml
# optional: true
continue-on-error: ${{ matrix.optional == true }}
steps:

17
backend/src/Squidex.Data.EntityFramework/AppDbContext.cs

@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using OpenIddict.EntityFrameworkCore.Models;
using Squidex.Assets.TusAdapter;
using Squidex.Domain.Apps.Entities.Apps;
using Squidex.Domain.Apps.Entities.Assets;
@ -54,6 +55,7 @@ public abstract class AppDbContext(DbContextOptions options, IJsonSerializer jso
builder.UseMigration();
builder.UseNames(jsonSerializer, jsonColumnType);
builder.UseOpenIddict();
builder.UseOpenIddictTokenType(Database.IsMySql());
builder.UseRequest(jsonSerializer, jsonColumnType);
builder.UseRules(jsonSerializer, jsonColumnType);
builder.UseSchema(jsonSerializer, jsonColumnType);
@ -73,6 +75,21 @@ public abstract class AppDbContext(DbContextOptions options, IJsonSerializer jso
internal static class Extensions
#pragma warning restore MA0048 // File name must match type name
{
public static void UseOpenIddictTokenType(this ModelBuilder builder, bool isMySql)
{
builder.Entity<OpenIddictEntityFrameworkCoreToken>(b =>
{
// OpenIddict 7 stores token type URNs with up to 57 characters, but the fork still limits the column to 50.
b.Property(x => x.Type).HasMaxLength(150);
if (isMySql)
{
// Keeps the index below the maximum key length of 3072 bytes with utf8mb4. Token types are unique within 50 characters.
b.HasIndex(x => new { x.ApplicationId, x.Status, x.Subject, x.Type }).HasPrefixLength(0, 0, 0, 50);
}
});
}
public static void UseIdentity(this ModelBuilder builder, IJsonSerializer jsonSerializer, string? jsonColumn)
{
builder.UseSnapshot<DefaultKeyStore.State>(jsonSerializer, jsonColumn);

1630
backend/src/Squidex.Data.EntityFramework/Providers/MySql/App/Migrations/20260915181445_WidenOpenIddictTokenType.Designer.cs

File diff suppressed because it is too large

63
backend/src/Squidex.Data.EntityFramework/Providers/MySql/App/Migrations/20260915181445_WidenOpenIddictTokenType.cs

@ -0,0 +1,63 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Squidex.Providers.MySql.App.Migrations
{
/// <inheritdoc />
public partial class WidenOpenIddictTokenType : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_OpenIddictTokens_ApplicationId_Status_Subject_Type",
table: "OpenIddictTokens");
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "OpenIddictTokens",
type: "varchar(150)",
maxLength: 150,
nullable: true,
oldClrType: typeof(string),
oldType: "varchar(50)",
oldMaxLength: 50,
oldNullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_OpenIddictTokens_ApplicationId_Status_Subject_Type",
table: "OpenIddictTokens",
columns: new[] { "ApplicationId", "Status", "Subject", "Type" })
.Annotation("MySql:IndexPrefixLength", new[] { 0, 0, 0, 50 });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_OpenIddictTokens_ApplicationId_Status_Subject_Type",
table: "OpenIddictTokens");
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "OpenIddictTokens",
type: "varchar(50)",
maxLength: 50,
nullable: true,
oldClrType: typeof(string),
oldType: "varchar(150)",
oldMaxLength: 150,
oldNullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_OpenIddictTokens_ApplicationId_Status_Subject_Type",
table: "OpenIddictTokens",
columns: new[] { "ApplicationId", "Status", "Subject", "Type" });
}
}
}

18
backend/src/Squidex.Data.EntityFramework/Providers/MySql/App/Migrations/MySqlDbContextModelSnapshot.cs

@ -18,7 +18,7 @@ namespace Squidex.Providers.MySql.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.5")
.HasAnnotation("ProductVersion", "10.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
@ -306,8 +306,8 @@ namespace Squidex.Providers.MySql.Migrations
.HasColumnType("varchar(400)");
b.Property<string>("Type")
.HasMaxLength(50)
.HasColumnType("varchar(50)");
.HasMaxLength(150)
.HasColumnType("varchar(150)");
b.HasKey("Id");
@ -316,7 +316,8 @@ namespace Squidex.Providers.MySql.Migrations
b.HasIndex("ReferenceId")
.IsUnique();
b.HasIndex("ApplicationId", "Status", "Subject", "Type");
b.HasIndex("ApplicationId", "Status", "Subject", "Type")
.HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0, 0, 50 });
b.ToTable("OpenIddictTokens", (string)null);
});
@ -330,14 +331,15 @@ namespace Squidex.Providers.MySql.Migrations
b.Property<DateTime>("LastUpdated")
.HasColumnType("datetime(6)");
b.Property<Guid>("LastVersion")
.IsConcurrencyToken()
.HasColumnType("char(36)")
.HasColumnName("Version");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("longtext");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("LastUpdated");

1630
backend/src/Squidex.Data.EntityFramework/Providers/Postgres/App/Migrations/20260915181452_WidenOpenIddictTokenType.Designer.cs

File diff suppressed because it is too large

40
backend/src/Squidex.Data.EntityFramework/Providers/Postgres/App/Migrations/20260915181452_WidenOpenIddictTokenType.cs

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Squidex.Providers.Postgres.App.Migrations
{
/// <inheritdoc />
public partial class WidenOpenIddictTokenType : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "OpenIddictTokens",
type: "character varying(150)",
maxLength: 150,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(50)",
oldMaxLength: 50,
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "OpenIddictTokens",
type: "character varying(50)",
maxLength: 50,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(150)",
oldMaxLength: 150,
oldNullable: true);
}
}
}

15
backend/src/Squidex.Data.EntityFramework/Providers/Postgres/App/Migrations/PostgresDbContextModelSnapshot.cs

@ -18,7 +18,7 @@ namespace Squidex.Providers.Postgres.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.5")
.HasAnnotation("ProductVersion", "10.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis");
@ -307,8 +307,8 @@ namespace Squidex.Providers.Postgres.Migrations
.HasColumnType("character varying(400)");
b.Property<string>("Type")
.HasMaxLength(50)
.HasColumnType("character varying(50)");
.HasMaxLength(150)
.HasColumnType("character varying(150)");
b.HasKey("Id");
@ -331,14 +331,15 @@ namespace Squidex.Providers.Postgres.Migrations
b.Property<DateTime>("LastUpdated")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("LastVersion")
.IsConcurrencyToken()
.HasColumnType("uuid")
.HasColumnName("Version");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("LastUpdated");

1632
backend/src/Squidex.Data.EntityFramework/Providers/SqlServer/App/Migrations/20260915181458_WidenOpenIddictTokenType.Designer.cs

File diff suppressed because it is too large

40
backend/src/Squidex.Data.EntityFramework/Providers/SqlServer/App/Migrations/20260915181458_WidenOpenIddictTokenType.cs

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Squidex.Providers.SqlServer.App.Migrations
{
/// <inheritdoc />
public partial class WidenOpenIddictTokenType : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "OpenIddictTokens",
type: "nvarchar(150)",
maxLength: 150,
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(50)",
oldMaxLength: 50,
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "OpenIddictTokens",
type: "nvarchar(50)",
maxLength: 50,
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(150)",
oldMaxLength: 150,
oldNullable: true);
}
}
}

15
backend/src/Squidex.Data.EntityFramework/Providers/SqlServer/App/Migrations/SqlServerDbContextModelSnapshot.cs

@ -18,7 +18,7 @@ namespace Squidex.Providers.SqlServer.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.5")
.HasAnnotation("ProductVersion", "10.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
@ -308,8 +308,8 @@ namespace Squidex.Providers.SqlServer.Migrations
.HasColumnType("nvarchar(400)");
b.Property<string>("Type")
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
.HasMaxLength(150)
.HasColumnType("nvarchar(150)");
b.HasKey("Id");
@ -333,14 +333,15 @@ namespace Squidex.Providers.SqlServer.Migrations
b.Property<DateTime>("LastUpdated")
.HasColumnType("datetime2");
b.Property<Guid>("LastVersion")
.IsConcurrencyToken()
.HasColumnType("uniqueidentifier")
.HasColumnName("Version");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<Guid>("Version")
.IsConcurrencyToken()
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("LastUpdated");

39
backend/tests/Squidex.Data.Tests/EntityFramework/Domain/Users/EFOpenIddictTests.cs

@ -48,4 +48,43 @@ public abstract class EFOpenIddictTests<TContext>(ISqlFixture<TContext> fixture)
await dbContext.SaveChangesAsync();
}
[Fact]
public async Task Should_roundtrip_openiddict_token_with_long_type_identifier()
{
// The longest token type has 57 characters.
var type = TokenTypeIdentifiers.Private.AuthorizationCode;
var tokenId = Guid.NewGuid().ToString();
var subject = Guid.NewGuid().ToString();
await using (var dbContext = await fixture.DbContextFactory.CreateDbContextAsync())
{
var token = new OpenIddictEntityFrameworkCoreToken
{
Id = tokenId,
ApplicationId = null,
CreationDate = DateTime.UtcNow,
ExpirationDate = DateTime.UtcNow.AddMinutes(5),
Status = Statuses.Valid,
Subject = subject,
Type = type,
};
dbContext.Set<OpenIddictEntityFrameworkCoreToken>().Add(token);
await dbContext.SaveChangesAsync();
}
await using (var dbContext = await fixture.DbContextFactory.CreateDbContextAsync())
{
// Compare the stored value, because not every database fails when it truncates.
var found =
await dbContext.Set<OpenIddictEntityFrameworkCoreToken>()
.Where(x => x.Subject == subject && x.Status == Statuses.Valid && x.Type == type)
.ToListAsync();
Assert.Equal(tokenId, Assert.Single(found).Id);
Assert.Equal(type, found[0].Type);
}
}
}

Loading…
Cancel
Save