feat: add platform public question bank workspace

This commit is contained in:
2026-07-30 12:18:14 +08:00
parent bf370605d4
commit 96c20a3b1d
17 changed files with 22100 additions and 212 deletions

View File

@@ -21,6 +21,10 @@ internal sealed class QuestionBankConfiguration : IEntityTypeConfiguration<Quest
.HasForeignKey(entity => new { entity.TenantId, entity.RegionId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne<ContentEntry>().WithMany()
.HasForeignKey(entity => new { entity.TenantId, entity.ContentEntryId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.Restrict);
}
}

View File

@@ -0,0 +1,80 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Tiku.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class AddPlatformQuestionBankWorkspace : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "content_entry_id",
table: "question_banks",
type: "uuid",
nullable: true);
migrationBuilder.Sql("""
INSERT INTO content_entries (
id, tenant_id, entry_key, name, entry_type, visibility,
access_rules, layout_config, sort_order, is_active, created_at, updated_at)
SELECT
qb.id,
qb.tenant_id,
'public-question-bank-' || replace(qb.id::text, '-', ''),
qb.name,
'question_practice',
'public',
'{}'::jsonb,
'{}'::jsonb,
0,
true,
qb.created_at,
qb.updated_at
FROM question_banks qb
JOIN tenants t ON t.id = qb.tenant_id AND t.mode = 'platform_owned'
WHERE NOT EXISTS (SELECT 1 FROM content_entries ce WHERE ce.id = qb.id);
UPDATE question_banks qb
SET content_entry_id = qb.id
FROM tenants t
WHERE t.id = qb.tenant_id
AND t.mode = 'platform_owned'
AND qb.content_entry_id IS NULL
AND EXISTS (SELECT 1 FROM content_entries ce WHERE ce.tenant_id = qb.tenant_id AND ce.id = qb.id);
""");
migrationBuilder.CreateIndex(
name: "ix_question_banks_tenant_id_content_entry_id",
table: "question_banks",
columns: new[] { "tenant_id", "content_entry_id" });
migrationBuilder.AddForeignKey(
name: "fk_question_banks_content_entries_tenant_id_content_entry_id",
table: "question_banks",
columns: new[] { "tenant_id", "content_entry_id" },
principalTable: "content_entries",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_question_banks_content_entries_tenant_id_content_entry_id",
table: "question_banks");
migrationBuilder.DropIndex(
name: "ix_question_banks_tenant_id_content_entry_id",
table: "question_banks");
migrationBuilder.DropColumn(
name: "content_entry_id",
table: "question_banks");
}
}
}

View File

@@ -14290,6 +14290,10 @@ namespace Tiku.Infrastructure.Persistence.Migrations
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<Guid?>("ContentEntryId")
.HasColumnType("uuid")
.HasColumnName("content_entry_id");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
@@ -14334,6 +14338,9 @@ namespace Tiku.Infrastructure.Persistence.Migrations
b.HasAlternateKey("TenantId", "Id")
.HasName("ak_question_banks_tenant_id_id");
b.HasIndex("TenantId", "ContentEntryId")
.HasDatabaseName("ix_question_banks_tenant_id_content_entry_id");
b.HasIndex("TenantId", "RegionId")
.HasDatabaseName("ix_question_banks_tenant_id_region_id");
@@ -19706,6 +19713,13 @@ namespace Tiku.Infrastructure.Persistence.Migrations
.IsRequired()
.HasConstraintName("fk_question_banks_tenants_tenant_id");
b.HasOne("Tiku.Domain.Content.ContentEntry", null)
.WithMany()
.HasForeignKey("TenantId", "ContentEntryId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict)
.HasConstraintName("fk_question_banks_content_entries_tenant_id_content_entry_id");
b.HasOne("Tiku.Domain.Catalog.Region", null)
.WithMany()
.HasForeignKey("TenantId", "RegionId")