public Task <int> Handle(UpgradeDatabaseCommand request, CancellationToken cancellationToken) { _logger.LogDebug("Running with Options={@DbUpOptions}", request); var connectionStringBuilder = new SqlConnectionStringBuilder(request.ConnectionString); var variables = new Dictionary <string, string> { { "environment", request.Environment }, { "login_name", connectionStringBuilder.UserID }, { "database_name", connectionStringBuilder.InitialCatalog }, }; UpgradeEngineBuilder builder = DeployChanges.To.SqlDatabase(request.ConnectionString) .WithScriptsFromFileSystem(request.ScriptsDirectory) .WithTransaction() .LogToLogger(_logger) .WithVariables(variables); if (!request.EnableJournaling) { builder = builder.JournalTo(new NullJournal()); } DatabaseUpgradeResult result = builder .Build() .PerformUpgrade(); return(Task.FromResult(result.Successful ? 0 : 1)); }
protected virtual DatabaseUpgradeResult ExecuteAlways(string connectionString, string scriptsPath, string configurationSpecificScriptsPath, IDictionary <string, string> variables) { DatabaseUpgradeResult result = new DatabaseUpgradeResult(new SqlScript[0], true, null); if (Directory.Exists(scriptsPath)) { UpgradeEngineBuilder engineBuilder = DeployChanges.To .SqlDatabase(connectionString) .WithScriptsFromFileSystem(scriptsPath); if (configurationSpecificScriptsPath != null) { engineBuilder = engineBuilder.WithScriptsFromFileSystem(configurationSpecificScriptsPath); } var engine = engineBuilder.JournalTo(new NullJournal()) .WithVariables(variables) .LogToConsole() .Build(); result = engine.PerformUpgrade(); } return(result); }
/// <summary> /// Method to change the journal between NullJournal and SqlTable journal. /// </summary> /// <param name="builder">The builder.</param> /// <param name="toggleNullJournal">if set to <c>true</c> configures the NullJournal.</param> /// <param name="table">The database table to save the journal.</param> /// <returns>The builder itself.</returns> /// <exception cref="ArgumentNullException">The database table to save the </exception> public static UpgradeEngineBuilder JournalToggle(this UpgradeEngineBuilder builder, bool toggleNullJournal = true, string table = null) { if (toggleNullJournal) { builder.JournalTo(new NullJournal()); } else { if (String.IsNullOrWhiteSpace(table)) { throw new ArgumentNullException(nameof(table)); } builder .JournalToSqlTable("dbo", table); } return(builder); }