Skip to content

Commit

Permalink
V2.3.5 (#39)
Browse files Browse the repository at this point in the history
* Version 2.3.5

* Set correct version for packages.

* Update CI for .NET 7.

* Fix test.
  • Loading branch information
chullybun committed Jun 24, 2023
1 parent cd781cc commit 9a21a02
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 138 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: |
6.0.x
7.0.x
- name: Restore dependencies
run: dotnet restore
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Represents the **NuGet** versions.

## v2.3.5
- *Enhancement:* Updated `CoreEx` to version `3.0.0`.
- *Enhancement:* Updated all dependent packages to latest versions.
- *Enhancement:* Added `net6.0` and `net7.0` support in addition to [.NET Standard](https://learn.microsoft.com/en-us/dotnet/standard/net-standard#when-to-target-net50-or-net60-vs-netstandard) to the `DbEx` packages. This will allow access to additional features per version where required, and overall performance improvements.
- *Enhancement:* Included C# code-generation templates updated; target `net6.0`+ only.

## v2.3.4
- *Fixed:* `MigrationArgsBase.Assemblies` internal list management simplified; all order/sequencing managed within `DatabaseMigrationBase` implementation to limit issues. Added a new `AddAssemblyAfter` to support explicit positioning where needed.

Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.3.4</Version>
<Version>2.3.5</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
9 changes: 7 additions & 2 deletions DbEx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{BB01353C-4
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbEx.SqlServer", "src\DbEx.SqlServer\DbEx.SqlServer.csproj", "{74DF6A5E-4F95-467A-8F64-5A4DBC3AAFFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbEx.MySql", "src\DbEx.MySql\DbEx.MySql.csproj", "{2B2BD40D-46FD-4582-994D-39D8056DE55E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbEx.MySql", "src\DbEx.MySql\DbEx.MySql.csproj", "{2B2BD40D-46FD-4582-994D-39D8056DE55E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbEx.Test.MySqlConsole", "tests\DbEx.Test.MySqlConsole\DbEx.Test.MySqlConsole.csproj", "{80EF0604-F641-4D01-9922-0162D0C69E02}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbEx.Test.MySqlConsole", "tests\DbEx.Test.MySqlConsole\DbEx.Test.MySqlConsole.csproj", "{80EF0604-F641-4D01-9922-0162D0C69E02}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Github Actions", "Github Actions", "{B208377A-6E7E-4E59-AD2F-34C9CB9A5E81}"
ProjectSection(SolutionItems) = preProject
.github\workflows\CI.yml = .github\workflows\CI.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
10 changes: 5 additions & 5 deletions src/DbEx.MySql/DbEx.MySql.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFrameworks>net6.0;net7.0;netstandard2.1</TargetFrameworks>
<RootNamespace>DbEx.MySql</RootNamespace>
<Product>DbEx</Product>
<Title>DbEx MySQL Migration Tool.</Title>
Expand Down Expand Up @@ -39,9 +39,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx.Database.MySql" Version="2.0.0" />
<PackageReference Include="dbup-mysql" Version="4.6.0" />
<PackageReference Include="OnRamp" Version="1.0.6" />
<PackageReference Include="CoreEx.Database.MySql" Version="3.0.0" />
<PackageReference Include="dbup-mysql" Version="5.0.10" />
<PackageReference Include="OnRamp" Version="1.0.7" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/DbEx.MySql/MySqlSchemaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public override string ToFormattedSqlType(DbColumnSchema schema, bool includeNul
Guid => $"'{value}'",
DateTime dt => $"'{dt.ToString(dataParserArgs.DateTimeFormat, System.Globalization.CultureInfo.InvariantCulture)}'",
DateTimeOffset dto => $"'{dto.ToString(dataParserArgs.DateTimeFormat, System.Globalization.CultureInfo.InvariantCulture)}'",
_ => value.ToString()
_ => value.ToString()!
};

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/DbEx.SqlServer/DbEx.SqlServer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFrameworks>net6.0;net7.0;netstandard2.1</TargetFrameworks>
<RootNamespace>DbEx.SqlServer</RootNamespace>
<Product>DbEx</Product>
<Title>DbEx SQL Server Migration Tool.</Title>
Expand Down Expand Up @@ -30,9 +30,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx.Database.SqlServer" Version="2.0.0" />
<PackageReference Include="dbup-sqlserver" Version="4.6.0" />
<PackageReference Include="OnRamp" Version="1.0.6" />
<PackageReference Include="CoreEx.Database.SqlServer" Version="3.0.0" />
<PackageReference Include="dbup-sqlserver" Version="5.0.8" />
<PackageReference Include="OnRamp" Version="1.0.7" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/DbEx.SqlServer/SqlServerSchemaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using DbEx.DbSchema;
using DbEx.Migration;
using DbEx.Migration.Data;
using OnRamp.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -219,7 +218,7 @@ public override string ToFormattedSqlType(DbColumnSchema schema, bool includeNul
Guid => $"'{value}'",
DateTime dt => $"'{dt.ToString(dataParserArgs.DateTimeFormat, System.Globalization.CultureInfo.InvariantCulture)}'",
DateTimeOffset dto => $"'{dto.ToString(dataParserArgs.DateTimeFormat, System.Globalization.CultureInfo.InvariantCulture)}'",
_ => value.ToString()
_ => value.ToString()!
};

/// <inheritdoc/>
Expand Down
38 changes: 16 additions & 22 deletions src/DbEx.SqlServer/Templates/EventOutboxDequeue_cs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,29 @@
* This file is automatically generated; any changes will be lost.
*/

{{#if Root.PreprocessorDirectives}}
#nullable enable
#pragma warning disable

using CoreEx.Database;
using CoreEx.Database.SqlServer.Outbox;
using CoreEx.Events;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Data;
{{/if}}
namespace {{NamespaceOutbox}}.Data;

namespace {{NamespaceOutbox}}.Data
/// <summary>
/// Provides the <see cref="EventSendData"/> <see cref="IDatabase">database</see> <i>outbox enqueue</i> <see cref="SendAsync(EventSendData[])"/>.
/// </summary>
public sealed class EventOutboxDequeue : EventOutboxDequeueBase
{
/// <summary>
/// Provides the <see cref="EventSendData"/> <see cref="IDatabase">database</see> <i>outbox enqueue</i> <see cref="SendAsync(EventSendData[])"/>.
/// Initializes a new instance of the <see cref="EventOutboxDequeue"/> class.
/// </summary>
public sealed class EventOutboxDequeue : EventOutboxDequeueBase
{
/// <summary>
/// Initializes a new instance of the <see cref="EventOutboxDequeue"/> class.
/// </summary>
/// <param name="database">The <see cref="IDatabase"/>.</param>
/// <param name="eventSender">The <see cref="IEventSender"/>.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param>
public EventOutboxDequeue(IDatabase database, IEventSender eventSender, ILogger<EventOutboxDequeue> logger) : base(database, eventSender, logger) { }
/// <param name="database">The <see cref="IDatabase"/>.</param>
/// <param name="eventSender">The <see cref="IEventSender"/>.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param>
public EventOutboxDequeue(IDatabase database, IEventSender eventSender, ILogger<EventOutboxDequeue> logger) : base(database, eventSender, logger) { }

/// <inheritdoc/>
protected override string DequeueStoredProcedure => "[{{OutboxSchema}}].[{{OutboxDequeueStoredProcedure}}]";
}
}
/// <inheritdoc/>
protected override string DequeueStoredProcedure => "[{{OutboxSchema}}].[{{OutboxDequeueStoredProcedure}}]";
}{{#if Root.PreprocessorDirectives}}

#pragma warning restore
#nullable restore
#nullable restore{{/if}}
39 changes: 17 additions & 22 deletions src/DbEx.SqlServer/Templates/EventOutboxEnqueue_cs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,31 @@
* This file is automatically generated; any changes will be lost.
*/

{{#if Root.PreprocessorDirectives}}
#nullable enable
#pragma warning disable

using CoreEx.Database;
using CoreEx.Database.SqlServer.Outbox;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Data;
{{/if}}
namespace {{NamespaceOutbox}}.Data;

namespace {{NamespaceOutbox}}.Data
/// <summary>
/// Provides the <see cref="EventSendData"/> <see cref="IDatabase">database</see> <i>outbox enqueue</i> <see cref="SendAsync(EventSendData[])"/>.
/// </summary>
public sealed class EventOutboxEnqueue : EventOutboxEnqueueBase
{
/// <summary>
/// Provides the <see cref="EventSendData"/> <see cref="IDatabase">database</see> <i>outbox enqueue</i> <see cref="SendAsync(EventSendData[])"/>.
/// Initializes a new instance of the <see cref="EventOutboxEnqueue"/> class.
/// </summary>
public sealed class EventOutboxEnqueue : EventOutboxEnqueueBase
{
/// <summary>
/// Initializes a new instance of the <see cref="EventOutboxEnqueue"/> class.
/// </summary>
/// <param name="database">The <see cref="IDatabase"/>.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param>
public EventOutboxEnqueue(IDatabase database, ILogger<EventOutboxEnqueue> logger) : base(database, logger) { }
/// <param name="database">The <see cref="IDatabase"/>.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param>
public EventOutboxEnqueue(IDatabase database, ILogger<EventOutboxEnqueue> logger) : base(database, logger) { }

/// <inheritdoc/>
protected override string DbTvpTypeName => "[{{OutboxSchema}}].[udt{{OutboxTable}}List]";
/// <inheritdoc/>
protected override string DbTvpTypeName => "[{{OutboxSchema}}].[udt{{OutboxTable}}List]";

/// <inheritdoc/>
protected override string EnqueueStoredProcedure => "[{{OutboxSchema}}].[{{OutboxEnqueueStoredProcedure}}]";
}
}
/// <inheritdoc/>
protected override string EnqueueStoredProcedure => "[{{OutboxSchema}}].[{{OutboxEnqueueStoredProcedure}}]";
}{{#if Root.PreprocessorDirectives}}

#pragma warning restore
#nullable restore
#nullable restore{{/if}}
2 changes: 1 addition & 1 deletion src/DbEx/Console/MigrationConsoleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public async Task<int> RunAsync(string[] args, CancellationToken cancellationTok
/// </summary>
/// <param name="option">The option name.</param>
/// <param name="action">The action to perform where <paramref name="option"/> is provided.</param>
protected void UpdateStringOption(string option, Action<string?> action)
protected void UpdateStringOption(string option, Action<string> action)
{
var co = GetCommandOption(option);
if (co != null && co.HasValue())
Expand Down
8 changes: 4 additions & 4 deletions src/DbEx/DbEx.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFrameworks>net6.0;net7.0;netstandard2.1</TargetFrameworks>
<RootNamespace>DbEx</RootNamespace>
<Product>DbEx</Product>
<Title>DbEx Database Migration Tool.</Title>
Expand All @@ -21,9 +21,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx.Database" Version="2.5.0" />
<PackageReference Include="dbup-sqlserver" Version="4.6.0" />
<PackageReference Include="OnRamp" Version="1.0.6" />
<PackageReference Include="CoreEx.Database" Version="3.0.0" />
<PackageReference Include="dbup-sqlserver" Version="5.0.8" />
<PackageReference Include="OnRamp" Version="1.0.7" />
</ItemGroup>

<Import Project="..\..\Common.targets" />
Expand Down
3 changes: 1 addition & 2 deletions src/DbEx/Migration/Data/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ internal DataTable(DataParser parser, string schema, string name)

SchemaTableName = $"'{(schema == string.Empty ? name : $"{schema}.{name}")}'";

DbTable = Parser.DbTables.Where(t => (!Parser.DatabaseSchemaConfig.SupportsSchema || t.Schema == schema) && t.Name == name).SingleOrDefault();
if (DbTable == null)
DbTable = Parser.DbTables.Where(t => (!Parser.DatabaseSchemaConfig.SupportsSchema || t.Schema == schema) && t.Name == name).SingleOrDefault() ??
throw new DataParserException($"Table {SchemaTableName} does not exist within the specified database.");

// Check that an identifier generator can be used.
Expand Down
14 changes: 7 additions & 7 deletions src/DbEx/Migration/DatabaseMigrationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void PreExecutionInitialization()
_hasInitialized = true;

var list = (List<string>)Namespaces;
Args.ProbeAssemblies.ForEach(x => list.Add(x.GetName().Name));
Args.ProbeAssemblies.ForEach(x => list.Add(x.GetName().Name!));

// Walk the assembly hierarchy.
var alist = new List<Assembly>();
Expand All @@ -246,7 +246,7 @@ private void PreExecutionInitialization()
alist.Add(type.Assembly);

type = type.BaseType;
} while (type != typeof(object));
} while (type != null && type != typeof(object));

var list2 = (List<Assembly>)ArtefactResourceAssemblies;
list2.AddRange(alist);
Expand Down Expand Up @@ -524,7 +524,7 @@ private async Task<bool> DatabaseSchemaAsync(CancellationToken cancellationToken
{
foreach (var fi in di.GetFiles("*.sql", SearchOption.AllDirectories))
{
var rn = $"{fi.FullName[(Args.OutputDirectory.Parent.FullName.Length + 1)..]}".Replace(' ', '_').Replace('-', '_').Replace('\\', '.').Replace('/', '.');
var rn = $"{fi.FullName[((Args.OutputDirectory?.Parent?.FullName.Length + 1) ?? 0)..]}".Replace(' ', '_').Replace('-', '_').Replace('\\', '.').Replace('/', '.');
scripts.Add(new DatabaseMigrationScript(fi, rn));
}
}
Expand Down Expand Up @@ -673,7 +673,7 @@ protected virtual async Task<bool> DatabaseResetAsync(CancellationToken cancella
var sql = cg.Generate(delete);

using var sr2 = new StringReader(sql);
string line;
string? line;
while ((line = sr2.ReadLine()) != null)
{
Logger.LogInformation("{Content}", $" {line}");
Expand Down Expand Up @@ -876,7 +876,7 @@ private async Task<bool> CreateScriptInternalAsync(string? name, IDictionary<str
var fi = new FileInfo(fn);

// Generate the script content and write to file system.
if (!fi.Directory.Exists)
if (!fi.Directory!.Exists)
fi.Directory.Create();

await File.WriteAllTextAsync(fi.FullName, new HandlebarsCodeGenerator(txt).Generate(data), cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -932,8 +932,8 @@ private async Task<bool> ExecuteSqlStatementsInternalAsync(string[]? statements,
/// <param name="sql">The SQL command.</param>
/// <returns>The resulting SQL command with runtime replacements make.</returns>
public string ReplaceSqlRuntimeParameters(string sql) => Args.Parameters.Count == 0
? sql : Regex.Replace(sql, "(" + string.Join("|", Args.Parameters.Select(x => $"{{{{{x.Key}}}}}").ToArray()) + ")", m => Args.Parameters.TryGetValue(m.Value[2..^2], out var pv)
? pv?.ToString() : throw new InvalidOperationException($"Runtime Parameter '{m.Value}' found within SQL command; a corresponding Parameter value has not been configured."));
? sql : Regex.Replace(sql, "(" + string.Join("|", Args.Parameters.Select(x => $"{{{{{x.Key}}}}}").ToArray()) + ")",
m => Args.Parameters.TryGetValue(m.Value[2..^2], out var pv) ? pv?.ToString()! : throw new InvalidOperationException($"Runtime Parameter '{m.Value}' found within SQL command; a corresponding Parameter value has not been configured."));

/// <inheritdoc/>
public void Dispose()
Expand Down
2 changes: 1 addition & 1 deletion src/DbEx/Migration/DatabaseMigrationScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public DatabaseMigrationScript(string sql, string name)
/// </summary>
public StreamReader GetStreamReader() => _assembly is not null
? new StreamReader(_assembly!.GetManifestResourceStream(Name)!)
: (_file is not null ? _file!.OpenText() : new StreamReader(new MemoryStream(Encoding.Default.GetBytes(_sql))));
: (_file is not null ? _file!.OpenText() : new StreamReader(new MemoryStream(Encoding.Default.GetBytes(_sql!))));
}
}
6 changes: 5 additions & 1 deletion src/DbEx/Migration/StringLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ namespace DbEx.Migration
/// </summary>
internal class StringLogger : ILogger
{
private readonly StringBuilder _stringBuilder = new StringBuilder();
private readonly StringBuilder _stringBuilder = new();
private readonly IExternalScopeProvider _scopeProvider = new LoggerExternalScopeProvider();

/// <inheritdoc/>
#if NET7_0_OR_GREATER
public IDisposable BeginScope<TState>(TState state) where TState : notnull => _scopeProvider.Push(state);
#else
public IDisposable BeginScope<TState>(TState state) => _scopeProvider.Push(state);
#endif

/// <inheritdoc/>
public bool IsEnabled(LogLevel logLevel) => true;
Expand Down
Loading

0 comments on commit 9a21a02

Please sign in to comment.