新增禁止删除列和禁止自动更新表结构的服务。只需要在列模型上增加DisableDeleteColummAttribute和DisableUpdateAttribute特性即可。

This commit is contained in:
Falcon 2024-10-25 10:46:15 +08:00
parent 0b6d923df7
commit 075ebb1fec
6 changed files with 61 additions and 3 deletions

View File

@ -0,0 +1,10 @@
using System;
namespace Falcon.SugarApi.DatabaseDefinitions
{
/// <summary>
/// 禁止删除表格的列
/// </summary>
[AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = true)]
public class DisableDeleteColummAttribute:Attribute { }
}

View File

@ -0,0 +1,10 @@
using System;
namespace Falcon.SugarApi.DatabaseDefinitions
{
/// <summary>
/// 禁止更新表结构
/// </summary>
[AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = true)]
public class DisableUpdateAttribute:Attribute { }
}

View File

@ -0,0 +1,18 @@
using SqlSugar;
using System;
namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
{
/// <summary>
/// 设置禁止删除列服务
/// </summary>
public class DisableDeleteColummService:IEntityTableServices
{
/// <inheritdoc/>
public void SetupTable(Type t,EntityInfo e) {
if(t.TryGetAttribute<DisableDeleteColummAttribute>(out var _)) {
e.IsDisabledDelete = true;
}
}
}
}

View File

@ -0,0 +1,18 @@
using SqlSugar;
using System;
namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
{
/// <summary>
/// 设置禁止升级表架构服务
/// </summary>
public class DisableUpdateAllService:IEntityTableServices
{
/// <inheritdoc/>
public void SetupTable(Type t,EntityInfo e) {
if(t.TryGetAttribute<DisableUpdateAttribute>(out var _)) {
e.IsDisabledUpdateAll = true;
}
}
}
}

View File

@ -42,6 +42,8 @@ namespace Falcon.SugarApi.DatabaseManager
var ces = config.ConfigureExternalServices;
ces.EntityNameService = (t,e) => {
new TableNameTableService().SetupTable(t,e);
new DisableDeleteColummService().SetupTable(t,e);
new DisableUpdateAllService().SetupTable(t,e);
};
ces.EntityService = (p,c) => {
new SetupKeyColumnServices().SetupColumn(p,c);