feat: add scoreline dynamic records

This commit is contained in:
xiong
2026-07-26 18:30:15 +08:00
parent fcf70db8aa
commit 5715869d29
19 changed files with 17069 additions and 13 deletions

View File

@@ -0,0 +1,63 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Tiku.Domain.Catalog;
namespace Tiku.Infrastructure.Persistence.Configurations;
internal sealed class ScorelineFieldConfiguration : IEntityTypeConfiguration<ScorelineField>
{
public void Configure(EntityTypeBuilder<ScorelineField> builder)
{
builder.ConfigureTenantEntity("scoreline_fields");
builder.ConfigureTimestamps();
builder.Property(entity => entity.LegacyId).HasMaxLength(64);
builder.Property(entity => entity.FieldKey).HasMaxLength(64);
builder.Property(entity => entity.FieldName).HasMaxLength(200);
builder.Property(entity => entity.FieldType).HasMaxLength(32);
builder.Property(entity => entity.Unit).HasMaxLength(32);
builder.Property(entity => entity.Options).IsJson("[]");
builder.Property(entity => entity.Placeholder).HasMaxLength(200);
builder.Property(entity => entity.Description).HasMaxLength(1000);
builder.HasIndex(entity => new { entity.TenantId, entity.LegacyId }).IsUnique();
builder.HasIndex(entity => new { entity.TenantId, entity.RegionId, entity.FieldKey }).IsUnique();
builder.HasIndex(entity => new { entity.TenantId, entity.RegionId, entity.IsFilter, entity.SortOrder });
builder.HasOne<Region>()
.WithMany()
.HasForeignKey(entity => new { entity.TenantId, entity.RegionId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.Restrict);
}
}
internal sealed class ScorelineRecordConfiguration : IEntityTypeConfiguration<ScorelineRecord>
{
public void Configure(EntityTypeBuilder<ScorelineRecord> builder)
{
builder.ConfigureTenantEntity("scoreline_records");
builder.ConfigureTimestamps();
builder.Property(entity => entity.LegacyId).HasMaxLength(64);
builder.Property(entity => entity.SchoolName).HasMaxLength(300);
builder.Property(entity => entity.MajorName).HasMaxLength(300);
builder.Property(entity => entity.FieldValues).IsJson("{}");
builder.HasIndex(entity => new { entity.TenantId, entity.LegacyId }).IsUnique();
builder.HasIndex(entity => new { entity.TenantId, entity.RegionId, entity.SchoolId, entity.MajorId, entity.Year });
builder.HasIndex(entity => new { entity.TenantId, entity.Year });
builder.HasOne<Region>()
.WithMany()
.HasForeignKey(entity => new { entity.TenantId, entity.RegionId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne<School>()
.WithMany()
.HasForeignKey(entity => new { entity.TenantId, entity.SchoolId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne<Major>()
.WithMany()
.HasForeignKey(entity => new { entity.TenantId, entity.MajorId })
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
.OnDelete(DeleteBehavior.Restrict);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Tiku.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class AddScorelineDynamicRecords : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "scoreline_fields",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column<Guid>(type: "uuid", nullable: true),
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
field_key = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
field_name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
field_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
unit = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
is_filter = table.Column<bool>(type: "boolean", nullable: false),
is_required = table.Column<bool>(type: "boolean", nullable: false),
is_visible = table.Column<bool>(type: "boolean", nullable: false),
is_trend = table.Column<bool>(type: "boolean", nullable: false),
options = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
placeholder = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
sort_order = table.Column<int>(type: "integer", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_scoreline_fields", x => x.id);
table.UniqueConstraint("ak_scoreline_fields_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_scoreline_fields_regions_tenant_id_region_id",
columns: x => new { x.tenant_id, x.region_id },
principalTable: "regions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_scoreline_fields_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "scoreline_records",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column<Guid>(type: "uuid", nullable: true),
school_id = table.Column<Guid>(type: "uuid", nullable: true),
major_id = table.Column<Guid>(type: "uuid", nullable: true),
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
year = table.Column<int>(type: "integer", nullable: false),
school_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
major_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
field_values = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_scoreline_records", x => x.id);
table.UniqueConstraint("ak_scoreline_records_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_scoreline_records_majors_tenant_id_major_id",
columns: x => new { x.tenant_id, x.major_id },
principalTable: "majors",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_scoreline_records_regions_tenant_id_region_id",
columns: x => new { x.tenant_id, x.region_id },
principalTable: "regions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_scoreline_records_schools_tenant_id_school_id",
columns: x => new { x.tenant_id, x.school_id },
principalTable: "schools",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_scoreline_records_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_scoreline_fields_tenant_id_legacy_id",
table: "scoreline_fields",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_scoreline_fields_tenant_id_region_id_field_key",
table: "scoreline_fields",
columns: new[] { "tenant_id", "region_id", "field_key" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_scoreline_fields_tenant_id_region_id_is_filter_sort_order",
table: "scoreline_fields",
columns: new[] { "tenant_id", "region_id", "is_filter", "sort_order" });
migrationBuilder.CreateIndex(
name: "ix_scoreline_records_tenant_id_legacy_id",
table: "scoreline_records",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_scoreline_records_tenant_id_major_id",
table: "scoreline_records",
columns: new[] { "tenant_id", "major_id" });
migrationBuilder.CreateIndex(
name: "ix_scoreline_records_tenant_id_region_id_school_id_major_id_ye~",
table: "scoreline_records",
columns: new[] { "tenant_id", "region_id", "school_id", "major_id", "year" });
migrationBuilder.CreateIndex(
name: "ix_scoreline_records_tenant_id_school_id",
table: "scoreline_records",
columns: new[] { "tenant_id", "school_id" });
migrationBuilder.CreateIndex(
name: "ix_scoreline_records_tenant_id_year",
table: "scoreline_records",
columns: new[] { "tenant_id", "year" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "scoreline_fields");
migrationBuilder.DropTable(
name: "scoreline_records");
}
}
}

View File

@@ -546,6 +546,204 @@ namespace Tiku.Infrastructure.Persistence.Migrations
b.ToTable("schools", (string)null);
});
modelBuilder.Entity("Tiku.Domain.Catalog.ScorelineField", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("now()");
b.Property<string>("Description")
.HasMaxLength(1000)
.HasColumnType("character varying(1000)")
.HasColumnName("description");
b.Property<string>("FieldKey")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("field_key");
b.Property<string>("FieldName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasColumnName("field_name");
b.Property<string>("FieldType")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("field_type");
b.Property<bool>("IsFilter")
.HasColumnType("boolean")
.HasColumnName("is_filter");
b.Property<bool>("IsRequired")
.HasColumnType("boolean")
.HasColumnName("is_required");
b.Property<bool>("IsTrend")
.HasColumnType("boolean")
.HasColumnName("is_trend");
b.Property<bool>("IsVisible")
.HasColumnType("boolean")
.HasColumnName("is_visible");
b.Property<string>("LegacyId")
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("legacy_id");
b.Property<JsonElement>("Options")
.ValueGeneratedOnAdd()
.HasColumnType("jsonb")
.HasColumnName("options")
.HasDefaultValueSql("'[]'::jsonb");
b.Property<string>("Placeholder")
.HasMaxLength(200)
.HasColumnType("character varying(200)")
.HasColumnName("placeholder");
b.Property<Guid?>("RegionId")
.HasColumnType("uuid")
.HasColumnName("region_id");
b.Property<int>("SortOrder")
.HasColumnType("integer")
.HasColumnName("sort_order");
b.Property<Guid>("TenantId")
.HasColumnType("uuid")
.HasColumnName("tenant_id");
b.Property<string>("Unit")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("unit");
b.Property<DateTimeOffset>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at")
.HasDefaultValueSql("now()");
b.HasKey("Id")
.HasName("pk_scoreline_fields");
b.HasAlternateKey("TenantId", "Id")
.HasName("ak_scoreline_fields_tenant_id_id");
b.HasIndex("TenantId", "LegacyId")
.IsUnique()
.HasDatabaseName("ix_scoreline_fields_tenant_id_legacy_id");
b.HasIndex("TenantId", "RegionId", "FieldKey")
.IsUnique()
.HasDatabaseName("ix_scoreline_fields_tenant_id_region_id_field_key");
b.HasIndex("TenantId", "RegionId", "IsFilter", "SortOrder")
.HasDatabaseName("ix_scoreline_fields_tenant_id_region_id_is_filter_sort_order");
b.ToTable("scoreline_fields", (string)null);
});
modelBuilder.Entity("Tiku.Domain.Catalog.ScorelineRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id")
.HasDefaultValueSql("gen_random_uuid()");
b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at")
.HasDefaultValueSql("now()");
b.Property<JsonElement>("FieldValues")
.ValueGeneratedOnAdd()
.HasColumnType("jsonb")
.HasColumnName("field_values")
.HasDefaultValueSql("'{}'::jsonb");
b.Property<string>("LegacyId")
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("legacy_id");
b.Property<Guid?>("MajorId")
.HasColumnType("uuid")
.HasColumnName("major_id");
b.Property<string>("MajorName")
.HasMaxLength(300)
.HasColumnType("character varying(300)")
.HasColumnName("major_name");
b.Property<Guid?>("RegionId")
.HasColumnType("uuid")
.HasColumnName("region_id");
b.Property<Guid?>("SchoolId")
.HasColumnType("uuid")
.HasColumnName("school_id");
b.Property<string>("SchoolName")
.HasMaxLength(300)
.HasColumnType("character varying(300)")
.HasColumnName("school_name");
b.Property<Guid>("TenantId")
.HasColumnType("uuid")
.HasColumnName("tenant_id");
b.Property<DateTimeOffset>("UpdatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at")
.HasDefaultValueSql("now()");
b.Property<int>("Year")
.HasColumnType("integer")
.HasColumnName("year");
b.HasKey("Id")
.HasName("pk_scoreline_records");
b.HasAlternateKey("TenantId", "Id")
.HasName("ak_scoreline_records_tenant_id_id");
b.HasIndex("TenantId", "LegacyId")
.IsUnique()
.HasDatabaseName("ix_scoreline_records_tenant_id_legacy_id");
b.HasIndex("TenantId", "MajorId")
.HasDatabaseName("ix_scoreline_records_tenant_id_major_id");
b.HasIndex("TenantId", "SchoolId")
.HasDatabaseName("ix_scoreline_records_tenant_id_school_id");
b.HasIndex("TenantId", "Year")
.HasDatabaseName("ix_scoreline_records_tenant_id_year");
b.HasIndex("TenantId", "RegionId", "SchoolId", "MajorId", "Year")
.HasDatabaseName("ix_scoreline_records_tenant_id_region_id_school_id_major_id_ye~");
b.ToTable("scoreline_records", (string)null);
});
modelBuilder.Entity("Tiku.Domain.Catalog.Subject", b =>
{
b.Property<Guid>("Id")
@@ -12499,6 +12697,54 @@ namespace Tiku.Infrastructure.Persistence.Migrations
.HasConstraintName("fk_schools_regions_tenant_id_region_id");
});
modelBuilder.Entity("Tiku.Domain.Catalog.ScorelineField", b =>
{
b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
.WithMany()
.HasForeignKey("TenantId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_scoreline_fields_tenants_tenant_id");
b.HasOne("Tiku.Domain.Catalog.Region", null)
.WithMany()
.HasForeignKey("TenantId", "RegionId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict)
.HasConstraintName("fk_scoreline_fields_regions_tenant_id_region_id");
});
modelBuilder.Entity("Tiku.Domain.Catalog.ScorelineRecord", b =>
{
b.HasOne("Tiku.Domain.Tenancy.Tenant", null)
.WithMany()
.HasForeignKey("TenantId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_scoreline_records_tenants_tenant_id");
b.HasOne("Tiku.Domain.Catalog.Major", null)
.WithMany()
.HasForeignKey("TenantId", "MajorId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict)
.HasConstraintName("fk_scoreline_records_majors_tenant_id_major_id");
b.HasOne("Tiku.Domain.Catalog.Region", null)
.WithMany()
.HasForeignKey("TenantId", "RegionId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict)
.HasConstraintName("fk_scoreline_records_regions_tenant_id_region_id");
b.HasOne("Tiku.Domain.Catalog.School", null)
.WithMany()
.HasForeignKey("TenantId", "SchoolId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict)
.HasConstraintName("fk_scoreline_records_schools_tenant_id_school_id");
});
modelBuilder.Entity("Tiku.Domain.Catalog.Subject", b =>
{
b.HasOne("Tiku.Domain.Tenancy.Tenant", null)

View File

@@ -41,6 +41,8 @@ public sealed class TikuDbContext(DbContextOptions<TikuDbContext> options) : DbC
public DbSet<Major> Majors => Set<Major>();
public DbSet<Subject> Subjects => Set<Subject>();
public DbSet<Category> Categories => Set<Category>();
public DbSet<ScorelineField> ScorelineFields => Set<ScorelineField>();
public DbSet<ScorelineRecord> ScorelineRecords => Set<ScorelineRecord>();
public DbSet<QuestionBank> QuestionBanks => Set<QuestionBank>();
public DbSet<Question> Questions => Set<Question>();
public DbSet<QuestionVersion> QuestionVersions => Set<QuestionVersion>();