Skip to content

Commit

Permalink
Resolve issue #12. (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun committed Apr 4, 2022
1 parent 2505ac5 commit 32c97af
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v1.0.6
- *Fixed:* [Issue 12](https://github.com/Avanade/DbEx/issues/12) fixed. Data import order has been reversed.

## v1.0.5
- *Enhancement:* The `EventOutboxEnqueueBase` is the SQL Server event outbox enqueue `IEventSender`. To minimize send latency (increasing real-time event delivery) a primary (alternate) `IEventSender` can be specified (`SetPrimaryEventSender`). This changes the event behaviour whereby the events will be sent via the specified primary first, then enqueued only where the primary fails. The events will still be written to the event outbox but as sent for audit purposes.

Expand Down
2 changes: 1 addition & 1 deletion src/DbEx/DbEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>DbEx</RootNamespace>
<Version>1.0.5</Version>
<Version>1.0.6</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>DbEx Developers</Authors>
<Company>Avanade</Company>
Expand Down
58 changes: 29 additions & 29 deletions src/DbEx/Migration/DatabaseMigratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ private async Task<bool> CommandExecuteAsync(MigrationCommand command, string ti
/// <remarks>This will also catch any unhandled exceptions and log accordingly.</remarks>
protected async Task<bool> CommandExecuteAsync(string title, Func<Task<bool>> action, Func<string>? summary = null)
{
Logger.LogInformation(string.Empty);
Logger.LogInformation(new string('-', 80));
Logger.LogInformation(string.Empty);
Logger.LogInformation(title ?? throw new ArgumentNullException(nameof(title)));
Logger.LogInformation("{Content}", string.Empty);
Logger.LogInformation("{Content}", new string('-', 80));
Logger.LogInformation("{Content}", string.Empty);
Logger.LogInformation("{Content}", title ?? throw new ArgumentNullException(nameof(title)));

try
{
Expand All @@ -207,13 +207,13 @@ protected async Task<bool> CommandExecuteAsync(string title, Func<Task<bool>> ac
return false;

sw.Stop();
Logger.LogInformation(string.Empty);
Logger.LogInformation($"Complete. [{sw.ElapsedMilliseconds}ms{summary?.Invoke() ?? string.Empty}]");
Logger.LogInformation("{Content}", string.Empty);
Logger.LogInformation("{Content}", $"Complete. [{sw.ElapsedMilliseconds}ms{summary?.Invoke() ?? string.Empty}]");
return true;
}
catch (Exception ex)
{
Logger.LogError(ex, ex.Message);
Logger.LogError(ex, "{Content}", ex.Message);
return false;
}
}
Expand All @@ -236,11 +236,11 @@ protected bool CheckDatabaseUpgradeResult(DatabaseUpgradeResult r)
if (r.Successful)
return true;

Logger.LogInformation(string.Empty);
Logger.LogInformation("{Content}", string.Empty);
if (r.ErrorScript?.Name != null)
Logger.LogError($"Error occured executing script '{r.ErrorScript.Name}': {r.Error.Message}");
Logger.LogError("{Content}", $"Error occured executing script '{r.ErrorScript.Name}': {r.Error.Message}");
else
Logger.LogError($"Unexpected error occured: {r.Error?.Message}");
Logger.LogError("{Content}", $"Unexpected error occured: {r.Error?.Message}");

return false;
}
Expand All @@ -264,7 +264,7 @@ protected bool CheckDatabaseUpgradeResult(DatabaseUpgradeResult r)
/// </summary>
private async Task<bool> DatabaseMigrateAsync()
{
Logger.LogInformation($" Probing for embedded resources: {string.Join(", ", GetNamespacesWithSuffix($"{MigrationsNamespace}.*.sql"))}");
Logger.LogInformation("{Content}", $" Probing for embedded resources: {string.Join(", ", GetNamespacesWithSuffix($"{MigrationsNamespace}.*.sql"))}");

var scripts = new List<SqlScript>();
foreach (var ass in Assemblies)
Expand All @@ -282,11 +282,11 @@ private async Task<bool> DatabaseMigrateAsync()

if (scripts.Count == 0)
{
Logger.LogInformation(NothingFoundText);
Logger.LogInformation("{Content}", NothingFoundText);
return true;
}

Logger.LogInformation(" Migrate (using DbUp) the embedded resources...");
Logger.LogInformation("{Content}", " Migrate (using DbUp) the embedded resources...");
return CheckDatabaseUpgradeResult(await ExecuteScriptsAsync(scripts, true).ConfigureAwait(false));
}

Expand All @@ -302,7 +302,7 @@ private async Task<bool> DatabaseSchemaAsync()
if (OutputDirectory != null)
{
var di = new DirectoryInfo(Path.Combine(OutputDirectory.FullName, SchemaNamespace));
Logger.LogInformation($" Probing for files (recursively): {Path.Combine(di.FullName, "*", "*.sql")}");
Logger.LogInformation("{Content}", $" Probing for files (recursively): {Path.Combine(di.FullName, "*", "*.sql")}");

if (di.Exists)
{
Expand All @@ -315,7 +315,7 @@ private async Task<bool> DatabaseSchemaAsync()
}

// Get all the resources from the assemblies.
Logger.LogInformation($" Probing for embedded resources: {string.Join(", ", GetNamespacesWithSuffix($"{SchemaNamespace}.*.sql"))}");
Logger.LogInformation("{Content}", $" Probing for embedded resources: {string.Join(", ", GetNamespacesWithSuffix($"{SchemaNamespace}.*.sql"))}");
foreach (var ass in Assemblies)
{
foreach (var rn in ass.GetManifestResourceNames().OrderBy(x => x))
Expand Down Expand Up @@ -363,10 +363,10 @@ private async Task<bool> DatabaseSchemaAsync()
/// </summary>
private async Task<bool> DatabaseDataAsync()
{
Logger.LogInformation($" Probing for embedded resources: {string.Join(", ", GetNamespacesWithSuffix($"{DataNamespace}.*.[sql|yaml]", true))}");
Logger.LogInformation("{Content}", $" Probing for embedded resources: {string.Join(", ", GetNamespacesWithSuffix($"{DataNamespace}.*.[sql|yaml]", true))}");

var list = new List<(Assembly Assembly, string ResourceName)>();
foreach (var ass in Assemblies)
foreach (var ass in Assemblies.Reverse<Assembly>()) // Reverse order as assumed data builds on earlier (e.g. master needs ref data).
{
foreach (var rn in ass.GetManifestResourceNames().OrderBy(x => x))
{
Expand All @@ -381,7 +381,7 @@ private async Task<bool> DatabaseDataAsync()
// Make sure there is work to be done.
if (list.Count == 0)
{
Logger.LogInformation(NothingFoundText);
Logger.LogInformation("{Content}", NothingFoundText);
return true;
}

Expand All @@ -400,8 +400,8 @@ private async Task<bool> DatabaseDataAsync()
if (item.ResourceName.EndsWith(".sql", StringComparison.InvariantCultureIgnoreCase))
{
// Execute the SQL script directly.
Logger.LogInformation(string.Empty);
Logger.LogInformation($"** Executing: {item.ResourceName}");
Logger.LogInformation("{Content}", string.Empty);
Logger.LogInformation("{Content}", $"** Executing: {item.ResourceName}");

var ss = new SqlScript(item.ResourceName, await sr.ReadToEndAsync().ConfigureAwait(false), new SqlScriptOptions { ScriptType = DbUp.Support.ScriptType.RunAlways });
var success = CheckDatabaseUpgradeResult(await ExecuteScriptsAsync(new SqlScript[] { ss }, false).ConfigureAwait(false));
Expand All @@ -413,8 +413,8 @@ private async Task<bool> DatabaseDataAsync()
// Handle the YAML - parse and execute.
try
{
Logger.LogInformation(string.Empty);
Logger.LogInformation($"** Parsing and executing: {item.ResourceName}");
Logger.LogInformation("{Content}", string.Empty);
Logger.LogInformation("{Content}", $"** Parsing and executing: {item.ResourceName}");

var tables = await parser.ParseYamlAsync(sr);

Expand All @@ -423,7 +423,7 @@ private async Task<bool> DatabaseDataAsync()
}
catch (DataParserException dpex)
{
Logger.LogError(dpex.Message);
Logger.LogError("{Content}", dpex.Message);
return false;
}
}
Expand Down Expand Up @@ -498,7 +498,7 @@ private async Task<bool> CreateScriptInternalAsync(string? resourceName = null,

if (sr == null)
{
Logger.LogError($"The Script resource '{resourceName}' does not exist.");
Logger.LogError("{Content}", $"The Script resource '{resourceName}' does not exist.");
return false;
}

Expand Down Expand Up @@ -541,7 +541,7 @@ private async Task<bool> CreateScriptInternalAsync(string? resourceName = null,

await File.WriteAllTextAsync(fi.FullName, new HandlebarsCodeGenerator(txt).Generate(data)).ConfigureAwait(false);

Logger.LogWarning($"Script file created: {fi.FullName}");
Logger.LogWarning("{Content}", $"Script file created: {fi.FullName}");
return true;
}

Expand Down Expand Up @@ -584,10 +584,10 @@ private async Task<bool> ExecuteSqlStatementsInternalAsync(params string[] state
Logger.LogInformation($" All scripts executed successfully.");
else
{
Logger.LogInformation(string.Empty);
Logger.LogError($"The SQL statement failed with: {dur.Error.Message}");
Logger.LogWarning($"Script '{dur.ErrorScript.Name}' contents:");
Logger.LogWarning(dur.ErrorScript.Contents);
Logger.LogInformation("{Content}", string.Empty);
Logger.LogError("{Content}", $"The SQL statement failed with: {dur.Error.Message}");
Logger.LogWarning("{Content}", $"Script '{dur.ErrorScript.Name}' contents:");
Logger.LogWarning("{Content}", dur.ErrorScript.Contents);
}

return dur.Successful;
Expand Down

0 comments on commit 32c97af

Please sign in to comment.