diff --git a/src/ZKEACMS.Updater/Service/DbUpdaterService.cs b/src/ZKEACMS.Updater/Service/DbUpdaterService.cs index c3088509..780301a7 100644 --- a/src/ZKEACMS.Updater/Service/DbUpdaterService.cs +++ b/src/ZKEACMS.Updater/Service/DbUpdaterService.cs @@ -31,6 +31,7 @@ public class DbUpdaterService : IDbUpdaterService private readonly IWebClient _webClient; private readonly ILogger _logger; private readonly IDBContextProvider _dbContextProvider; + private readonly bool isDevelopment; private const int DBVersionRecord = 1; private readonly string _scriptFileName; private string availableSource; @@ -38,13 +39,15 @@ public DbUpdaterService(DatabaseOption databaseOption, IOptions dbVersionOption, IWebClient webClient, IDBContextProvider dbContextProvider, - ILogger logger) + ILogger 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() @@ -141,6 +144,8 @@ private void SaveVersionToFile(Easy.Version version) { try { + if (isDevelopment) return; + var plugPath = PluginBase.GetPath(); var versionFile = Path.Combine(plugPath, "appsettings.json"); _dbVersionOption.DBVersion = version.ToString(); @@ -388,6 +393,7 @@ private bool ExecuteScripts(DbContext dbContext, IEnumerable sqlScripts) foreach (var sql in sqlScripts) { if (sql.IsNullOrWhiteSpace()) continue; + using (var command = dbConnection.CreateCommand()) { command.Transaction = dbTransaction; @@ -397,9 +403,7 @@ private bool ExecuteScripts(DbContext dbContext, IEnumerable sqlScripts) } } - dbTransaction.Commit(); - return true; } catch (Exception ex) @@ -414,7 +418,6 @@ private bool ExecuteScripts(DbContext dbContext, IEnumerable sqlScripts) dbConnection.Close(); } } - } return false; } diff --git a/src/ZKEACMS.Updater/appsettings.json b/src/ZKEACMS.Updater/appsettings.json index 7165174d..763abcab 100644 --- a/src/ZKEACMS.Updater/appsettings.json +++ b/src/ZKEACMS.Updater/appsettings.json @@ -1,6 +1,5 @@ { "DBVersionOption": { - "DBVersion": "4.0.0.0", "BaseVersion": "3.3.5", "Source": [ "https://gitee.com/seriawei/ZKEACMS.Core/raw/develop/Database",