Skip to content

Commit

Permalink
Do not update dbversion to file in develop environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
SeriaWei committed Sep 21, 2024
1 parent aed56f4 commit ae10770
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/ZKEACMS.Updater/Service/DbUpdaterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ public class DbUpdaterService : IDbUpdaterService
private readonly IWebClient _webClient;
private readonly ILogger<DbUpdaterService> _logger;
private readonly IDBContextProvider _dbContextProvider;
private readonly bool isDevelopment;
private const int DBVersionRecord = 1;
private readonly string _scriptFileName;
private string availableSource;
public DbUpdaterService(DatabaseOption databaseOption,
IOptions<DBVersionOption> dbVersionOption,
IWebClient webClient,
IDBContextProvider dbContextProvider,
ILogger<DbUpdaterService> logger)
ILogger<DbUpdaterService> logger,
IWebHostEnvironment hostEnvironment)
{
_dbVersionOption = dbVersionOption.Value;
_webClient = webClient;
_scriptFileName = $"{databaseOption.DbType}.sql";//MsSql.sql, MySql.sql, Sqlite.sql
_logger = logger;
_dbContextProvider = dbContextProvider;
isDevelopment = hostEnvironment.IsDevelopment();
}

public void UpdateDatabase()
Expand Down Expand Up @@ -141,6 +144,8 @@ private void SaveVersionToFile(Easy.Version version)
{
try
{
if (isDevelopment) return;

var plugPath = PluginBase.GetPath<UpdaterPlug>();
var versionFile = Path.Combine(plugPath, "appsettings.json");
_dbVersionOption.DBVersion = version.ToString();
Expand Down Expand Up @@ -388,6 +393,7 @@ private bool ExecuteScripts(DbContext dbContext, IEnumerable<string> sqlScripts)
foreach (var sql in sqlScripts)
{
if (sql.IsNullOrWhiteSpace()) continue;

using (var command = dbConnection.CreateCommand())
{
command.Transaction = dbTransaction;
Expand All @@ -397,9 +403,7 @@ private bool ExecuteScripts(DbContext dbContext, IEnumerable<string> sqlScripts)
}
}


dbTransaction.Commit();

return true;
}
catch (Exception ex)
Expand All @@ -414,7 +418,6 @@ private bool ExecuteScripts(DbContext dbContext, IEnumerable<string> sqlScripts)
dbConnection.Close();
}
}

}
return false;
}
Expand Down
1 change: 0 additions & 1 deletion src/ZKEACMS.Updater/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"DBVersionOption": {
"DBVersion": "4.0.0.0",
"BaseVersion": "3.3.5",
"Source": [
"https://gitee.com/seriawei/ZKEACMS.Core/raw/develop/Database",
Expand Down

0 comments on commit ae10770

Please sign in to comment.