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