判断系统是否是第一次启动,是则强制初始化数据库和种子数据
This commit is contained in:
parent
747def5163
commit
14c8f97e64
@ -361,8 +361,11 @@ public static class SqlSugarSetup
|
||||
{
|
||||
SqlSugarScopeProvider dbProvider = db.GetConnectionScope(config.ConfigId);
|
||||
|
||||
// 判断系统是否是第一次启动,是则强制初始化数据库和种子数据
|
||||
bool isfirst = dbProvider.CurrentConnectionConfig.ConfigId.ToString() == SqlSugarConst.MainConfigId && !dbProvider.DbMaintenance.IsAnyTable(nameof(SysConfig));
|
||||
|
||||
// 初始化/创建数据库
|
||||
if (config.DbSettings.EnableInitDb)
|
||||
if (config.DbSettings.EnableInitDb || isfirst)
|
||||
{
|
||||
Log.Information($"初始化数据库 {config.DbType} - {config.ConfigId} - {config.ConnectionString}");
|
||||
if (config.DbType != SqlSugar.DbType.Oracle) dbProvider.DbMaintenance.CreateDatabase();
|
||||
@ -372,7 +375,7 @@ public static class SqlSugarSetup
|
||||
var (startups, oldVerion, currentVersion) = BeforeInitTable(dbProvider, config);
|
||||
|
||||
// 初始化表结构
|
||||
if (config.TableSettings.EnableInitTable)
|
||||
if (config.TableSettings.EnableInitTable || isfirst)
|
||||
{
|
||||
Log.Information($"初始化表结构 {config.DbType} - {config.ConfigId}");
|
||||
var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false))
|
||||
@ -410,7 +413,7 @@ public static class SqlSugarSetup
|
||||
}
|
||||
|
||||
// 初始化种子数据
|
||||
if (config.SeedSettings.EnableInitSeed) InitSeedData(db, config);
|
||||
if (config.SeedSettings.EnableInitSeed || isfirst) InitSeedData(db, config);
|
||||
|
||||
// 初始化种子数据之后——系统版本号
|
||||
AfterInitSeed(dbProvider, config, startups, oldVerion, currentVersion);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user