45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|||
|
|
|
||
|
|
namespace MiGu.DB.Abstractions.Runtime;
|
||
|
|
|
||
|
|
public interface IActorContext
|
||
|
|
{
|
||
|
|
string Name { get; }
|
||
|
|
}
|
||
|
|
|
||
|
|
public interface IActorContextAccessor
|
||
|
|
{
|
||
|
|
IActorContext Current { get; set; }
|
||
|
|
}
|
||
|
|
|
||
|
|
public interface IDataMigrator
|
||
|
|
{
|
||
|
|
int Order { get; }
|
||
|
|
string Name { get; }
|
||
|
|
Task MigrateAsync(DbContext db, CancellationToken ct = default);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 启动期 Schema 初始化策略。
|
||
|
|
/// <see cref="Migrate"/>:版本化迁移(发版/现场);
|
||
|
|
/// <see cref="EnsureCreated"/>:按当前模型建库(开发期,改模型需删库重建)。
|
||
|
|
/// </summary>
|
||
|
|
public enum MiGuSchemaMode
|
||
|
|
{
|
||
|
|
Migrate = 0,
|
||
|
|
EnsureCreated = 1
|
||
|
|
}
|
||
|
|
|
||
|
|
public sealed class MiGuDbOptions
|
||
|
|
{
|
||
|
|
public string Provider { get; set; } = "sqlite";
|
||
|
|
public string ConnectionString { get; set; } = "";
|
||
|
|
public string ContentRootPath { get; set; } = "";
|
||
|
|
|
||
|
|
/// <summary>Schema 初始化模式,对应配置 Database:SchemaMode。</summary>
|
||
|
|
public MiGuSchemaMode SchemaMode { get; set; } = MiGuSchemaMode.Migrate;
|
||
|
|
|
||
|
|
/// <summary>为 true 时,Schema 初始化后按 Order 执行全部 IDataMigrator(默认开启)。</summary>
|
||
|
|
public bool ApplyDataMigratorsOnStartup { get; set; } = true;
|
||
|
|
}
|