后期表索引类型更改,同时不影响之前的表
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
a5155457b1
commit
ccf16423d2
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -52,4 +52,7 @@
|
|||
|
||||
5、以下命令将生成一个从指定 from 迁移到指定 to 迁移的 SQL 脚本。
|
||||
|
||||
dotnet ef migrations script from to -p IRaCIS.Core.Infra.EFCore
|
||||
dotnet ef migrations script from to -p IRaCIS.Core.Infra.EFCore
|
||||
|
||||
6、查看迁移列表
|
||||
dotnet ef migrations list -p IRaCIS.Core.Infra.EFCore
|
||||
|
|
@ -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️ 所有 Entity:Id 为主键(非聚集)
|
||||
if (typeof(Entity).IsAssignableFrom(entityType.ClrType))
|
||||
{
|
||||
modelBuilder.Entity(entityType.ClrType)
|
||||
.HasKey(nameof(Entity.Id))
|
||||
.IsClustered(false);
|
||||
}
|
||||
|
||||
// 2️ 所有 IAuditAdd:CreateTime 为聚集索引
|
||||
if (typeof(IAuditAdd).IsAssignableFrom(entityType.ClrType))
|
||||
{
|
||||
modelBuilder.Entity(entityType.ClrType)
|
||||
.HasIndex(nameof(IAuditAdd.CreateTime))
|
||||
.IsClustered();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// 软删除配置
|
||||
if (typeof(ISoftDelete).IsAssignableFrom(entityType.ClrType))
|
||||
{
|
||||
|
|
@ -694,7 +727,7 @@ public class IRaCISDBContext : DbContext
|
|||
|
||||
public virtual DbSet<AuditDocumentClosure> AuditDocumentClosure { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class TestLength : Entity
|
||||
|
|
|
|||
21464
IRaCIS.Core.Infra.EFCore/Migrations/20260110112346_clusterModify.Designer.cs
generated
Normal file
21464
IRaCIS.Core.Infra.EFCore/Migrations/20260110112346_clusterModify.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue