后期表索引类型更改,同时不影响之前的表
continuous-integration/drone/push Build is passing Details

Test_IRC_Net8
hang 2026-01-10 19:30:47 +08:00
parent a5155457b1
commit ccf16423d2
6 changed files with 33038 additions and 694 deletions

View File

@ -12,6 +12,7 @@ using IRaCIS.Core.Domain;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infra.EFCore;
using IRaCIS.Core.Infra.EFCore.Context;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Infrastructure.Encryption;
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
@ -75,6 +76,25 @@ namespace IRaCIS.Core.Application.Service
{
public static int IntValue = 100;
[AllowAnonymous]
public async Task<IResponseOutput> CreatNewDBStruct()
{
var factory = new IRaCISDBContextFactory();
using var db = factory.CreateDbContext(Array.Empty<string>());
// ⚠️ 临时用,确认是测试库
// db.Database.EnsureDeleted();
db.Database.EnsureCreated();
Console.WriteLine("数据库结构已创建完成");
return ResponseOutput.Ok();
}
[AllowAnonymous]
public async Task<IResponseOutput> TestOSS(StorageClass storageClass)
{

View File

@ -53,3 +53,6 @@
5、以下命令将生成一个从指定 from 迁移到指定 to 迁移的 SQL 脚本。
dotnet ef migrations script from to -p IRaCIS.Core.Infra.EFCore
6、查看迁移列表
dotnet ef migrations list -p IRaCIS.Core.Infra.EFCore

View File

@ -6,6 +6,7 @@ using IRaCIS.Core.Infrastructure.Extention;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
@ -60,8 +61,13 @@ public class IRaCISDBContext : DbContext
//针对字符串使用默认的长度配置为200如果标注了StringLength 其他长度就是标注的长度如果标注了MaxLength 那么就是nvarcharMax
configurationBuilder.Conventions.Add(_ => new DefaultStringLengthConvention(400));
//configurationBuilder.Conventions.Add(_ => new RemoveForeignKeyConvention());
//控制外键索引生成与否
//https://learn.microsoft.com/zh-cn/ef/core/modeling/relationships/conventions?utm_source=chatgpt.com
//configurationBuilder.Conventions.Remove(typeof(ForeignKeyIndexConvention));
configurationBuilder.Conventions.Remove(typeof(ForeignKeyIndexConvention));
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
@ -116,6 +122,7 @@ public class IRaCISDBContext : DbContext
#region decimal 自定义精度,适配多种数据库
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
foreach (var property in entityType.GetProperties())
@ -142,6 +149,12 @@ public class IRaCISDBContext : DbContext
}
}
//用户名区分大小写
modelBuilder.Entity<IdentityUser>(entity =>
{
entity.Property(e => e.UserName)
.UseCollation("Chinese_PRC_CS_AS");
});
#endregion
//遍历实体模型手动配置
@ -160,6 +173,26 @@ public class IRaCISDBContext : DbContext
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
#region 修改Id 聚集索引-> Id非聚集CreateTime聚集索引方便分区
// 1 所有 EntityId 为主键(非聚集)
if (typeof(Entity).IsAssignableFrom(entityType.ClrType))
{
modelBuilder.Entity(entityType.ClrType)
.HasKey(nameof(Entity.Id))
.IsClustered(false);
}
// 2 所有 IAuditAddCreateTime 为聚集索引
if (typeof(IAuditAdd).IsAssignableFrom(entityType.ClrType))
{
modelBuilder.Entity(entityType.ClrType)
.HasIndex(nameof(IAuditAdd.CreateTime))
.IsClustered();
}
#endregion
// 软删除配置
if (typeof(ISoftDelete).IsAssignableFrom(entityType.ClrType))
{

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff