Skip to content

Commit

Permalink
v2.5.0 (#51)
Browse files Browse the repository at this point in the history
* PostgreSQL support.

* Migrate to CoreEx.Text.SentenceCase

* Additional fixes and doco.

* Column name default improvements.

* Finalize.

* Update CI
Fix compile error.

* Change postgres docker password

* Password typo.
  • Loading branch information
chullybun committed Feb 26, 2024
1 parent df5ddd6 commit d727345
Show file tree
Hide file tree
Showing 90 changed files with 1,969 additions and 710 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ jobs:

- name: Start MySQL
run: docker run --name db-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=yourStrong#!Password -d mysql

- name: Pull Postgres
run: docker pull postgres

- name: Start Postgres
run: docker run --name db-postgres -p 5432:5432 -e POSTGRES_PASSWORD=yourStrong#!Password -d postgres

- name: Sleep (allow SqlServer and MySQL to complete startup)
- name: Sleep (allow databases to complete startup)
run: sleep 10

- name: Set EnvVar for Test
Expand All @@ -50,6 +56,7 @@ jobs:
echo "DbEx_ConnectionStrings__EmptyDb=Data Source=localhost, 1433;Initial Catalog=DbEx.Empty;User id=sa;Password=yourStrong(!)Password;TrustServerCertificate=true" >> $GITHUB_ENV
echo "DbEx_ConnectionStrings__ConsoleDb=Data Source=localhost, 1433;Initial Catalog=DbEx.Console;User id=sa;Password=yourStrong(!)Password;TrustServerCertificate=true" >> $GITHUB_ENV
echo "DbEx_ConnectionStrings__MySqlDb=Server=localhost; Port=3306; Database=dbex_test; Uid=root; Pwd=yourStrong#!Password;" >> $GITHUB_ENV
echo "DbEx_ConnectionStrings__PostgresDb=Server=localhost; Port=5432; Database=dbex_test; Username=postgres; Pwd=yourStrong#!Password; Pooling=false" >> $GITHUB_ENV
- name: Test
run: dotnet test --no-build --verbosity normal
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

Represents the **NuGet** versions.

## v2.5.0
- *Enhancement:* Added [PostgreSQL](https://www.postgresql.org/) database migrations support.
- *Enhancement:* Added `DateOnly` and `TimeOnly` support (requires `net7.0`+) (see also `MigrationArgs.EmitDotNetDateOnly` and `MigrationArgs.EmitDotNetTimeOnly` to explicitly enable).
- *Enhamcement:* Improved the `MigrationArgs` support throughout to simplify usage, and improve configurablility and consistency; enabling greater flexibility to control the migration process/activities.
- *Internal*:
- All `throw new ArgumentNullException` checking migrated to the `xxx.ThrowIfNull` extension method equivalent.
- All _Run Code Analysis_ issues resolved.

## v2.4.0
- *Enhancement:* Added `MigrationAssemblyArgs` to allow for the specification of zero or more `Data` folder names.
- *Fixed:* Updated `CoreEx` to version `3.9.0`.


## v2.3.15
- *Fixed:* Updated `CoreEx` to version `3.8.0`.
- *Fixed:* Updated `OnRamp` to version `2.0.0` which necessitated internal change from `Newtonsoft.Json` (now deprecated) to `System.Text.Json`; additionally, the `DataParser` was refactored accordingly.
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.4.0</Version>
<Version>2.5.0</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
13 changes: 13 additions & 0 deletions DbEx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Github Actions", "Github Ac
.github\workflows\CI.yml = .github\workflows\CI.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbEx.Postgres", "src\DbEx.Postgres\DbEx.Postgres.csproj", "{C0ADA5D9-8952-4E0F-9865-2968FEACFC9A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbEx.Test.PostgresConsole", "tests\DbEx.Test.PostgresConsole\DbEx.Test.PostgresConsole.csproj", "{9DBC4E5E-6321-4F56-82CC-7ECEE1020EE0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -90,6 +94,14 @@ Global
{80EF0604-F641-4D01-9922-0162D0C69E02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80EF0604-F641-4D01-9922-0162D0C69E02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80EF0604-F641-4D01-9922-0162D0C69E02}.Release|Any CPU.Build.0 = Release|Any CPU
{C0ADA5D9-8952-4E0F-9865-2968FEACFC9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0ADA5D9-8952-4E0F-9865-2968FEACFC9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0ADA5D9-8952-4E0F-9865-2968FEACFC9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0ADA5D9-8952-4E0F-9865-2968FEACFC9A}.Release|Any CPU.Build.0 = Release|Any CPU
{9DBC4E5E-6321-4F56-82CC-7ECEE1020EE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DBC4E5E-6321-4F56-82CC-7ECEE1020EE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DBC4E5E-6321-4F56-82CC-7ECEE1020EE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DBC4E5E-6321-4F56-82CC-7ECEE1020EE0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -102,6 +114,7 @@ Global
{959DD5E1-530A-42BA-82B8-F17A657AC351} = {06385968-DFF7-4470-B87E-55D98CC4661C}
{2069346C-9769-48DF-B71F-A58ED6A2192B} = {06385968-DFF7-4470-B87E-55D98CC4661C}
{80EF0604-F641-4D01-9922-0162D0C69E02} = {06385968-DFF7-4470-B87E-55D98CC4661C}
{9DBC4E5E-6321-4F56-82CC-7ECEE1020EE0} = {06385968-DFF7-4470-B87E-55D98CC4661C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1A02148E-CFB1-43D0-8DC0-123232A179A7}
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Package | Status | Source & documentation
-|-|-
`DbEx` | [![NuGet version](https://badge.fury.io/nu/DbEx.svg)](https://badge.fury.io/nu/DbEx) | [Link](./src/DbEx)
`DbEx.MySql` | [![NuGet version](https://badge.fury.io/nu/DbEx.MySql.svg)](https://badge.fury.io/nu/DbEx.MySql) | [Link](./src/DbEx.MySql)
`DbEx.Postgres` | [![NuGet version](https://badge.fury.io/nu/DbEx.Postgres.svg)](https://badge.fury.io/nu/DbEx.Postgres) | [Link](./src/DbEx.Postgres)
`DbEx.SqlServer` | [![NuGet version](https://badge.fury.io/nu/DbEx.SqlServer.svg)](https://badge.fury.io/nu/DbEx.SqlServer) | [Link](./src/DbEx.SqlServer)


Expand Down Expand Up @@ -313,8 +314,8 @@ To simplify the database management here are some further considerations that ma
## Other repos

These other _Avanade_ repositories leverage _DbEx_:
- [NTangle](https://github.com/Avanade/NTangle) - Change Data Capture (CDC) code generation tool and runtime.
- [Beef](https://github.com/Avanade/Beef) - Business Entity Execution Framework to enable industralisation of API development.
- [*NTangle*](https://github.com/Avanade/NTangle) - Change Data Capture (CDC) code generation tool and runtime.
- [*Beef*](https://github.com/Avanade/Beef) - Business Entity Execution Framework to enable industralisation of API development.

<br/>

Expand Down
1 change: 1 addition & 0 deletions nuget-publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ param(
[String[]]$ProjectsToPublish = @(
"src\DbEx",
"src\DbEx.MySql",
"src\DbEx.Postgres",
"src\DbEx.SqlServer")
)

Expand Down
3 changes: 2 additions & 1 deletion src/DbEx.MySql/Console/MySqlMigrationConsole.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx

using CoreEx;
using DbEx.Console;
using DbEx.Migration;
using DbEx.MySql.Migration;
Expand Down Expand Up @@ -32,7 +33,7 @@ public sealed class MySqlMigrationConsole : MigrationConsoleBase<MySqlMigrationC
/// Initializes a new instance of the <see cref="MySqlMigrationConsole"/> class that provides a default for the <paramref name="connectionString"/>.
/// </summary>
/// <param name="connectionString">The database connection string.</param>
public MySqlMigrationConsole(string connectionString) : base(new MigrationArgs { ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString)) }) { }
public MySqlMigrationConsole(string connectionString) : base(new MigrationArgs { ConnectionString = connectionString.ThrowIfNull(nameof(connectionString)) }) { }

/// <summary>
/// Gets the <see cref="MigrationArgs"/>.
Expand Down
6 changes: 4 additions & 2 deletions src/DbEx.MySql/DbEx.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
<None Remove="Resources\ScriptCreate_sql.hbs" />
<None Remove="Resources\ScriptDefault_sql.hbs" />
<None Remove="Resources\ScriptRefData_sql.hbs" />
<None Remove="Resources\SelectTableAndColumns.sql" />
<None Remove="Resources\SelectTableForeignKeys.sql" />
<None Remove="Resources\SelectTablePrimaryKey.sql" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx.Database.MySql" Version="3.9.0" />
<PackageReference Include="dbup-mysql" Version="5.0.37" />
<PackageReference Include="CoreEx.Database.MySql" Version="3.12.0" />
<PackageReference Include="dbup-mysql" Version="5.0.40" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions src/DbEx.MySql/Migration/MySqlMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ namespace DbEx.MySql.Migration
/// <summary>
/// Provides the <see href="https://dev.mysql.com/">MySQL</see> migration orchestration.
/// </summary>
/// <remarks>The following <see cref="DatabaseMigrationBase.SchemaObjectTypes"/> are supported by default: '<c>TYPE</c>', '<c>FUNCTION</c>', '<c>VIEW</c>', '<c>PROCEDURE</c>' and '<c>PROC</c>'.
/// <para>Where the <see cref="DatabaseMigrationBase.Args"/> <see cref="MigrationArgsBase.DataResetFilterPredicate"/> is not specified it will default to '<c>schema => schema.Schema != "dbo" || schema.Schema != "cdc"</c>' which will
/// filter out a data reset where a table is in the '<c>dbo</c>' and '<c>cdc</c>' schemas.</para>
/// <para>The base <see cref="DatabaseMigrationBase.Journal"/> instance is updated; the <see cref="IDatabaseJournal.Schema"/> and <see cref="IDatabaseJournal.Table"/> properties are set to `<c>dbo</c>` and `<c>SchemaVersions</c>` respectively.</para></remarks>
/// <remarks>The following <see cref="DatabaseMigrationBase.SchemaObjectTypes"/> are supported by default: ''<c>FUNCTION</c>', '<c>VIEW</c>', '<c>PROCEDURE</c>'.
/// <para>The base <see cref="DatabaseMigrationBase.Journal"/> instance is updated; the <see cref="IDatabaseJournal.Schema"/> and <see cref="IDatabaseJournal.Table"/> properties are set to `<c>null</c>` and `<c>schemaversions</c>` respectively.</para></remarks>
public class MySqlMigration : DatabaseMigrationBase
{
private readonly string _databaseName;
Expand All @@ -33,6 +31,8 @@ public class MySqlMigration : DatabaseMigrationBase
/// <param name="args">The <see cref="MigrationArgsBase"/>.</param>
public MySqlMigration(MigrationArgsBase args) : base(args)
{
SchemaConfig = new MySqlSchemaConfig(this);

var csb = new MySqlConnectionStringBuilder(Args.ConnectionString);
_databaseName = csb.Database;
if (string.IsNullOrEmpty(_databaseName))
Expand All @@ -51,9 +51,9 @@ public MySqlMigration(MigrationArgsBase args) : base(args)
SchemaObjectTypes = ["FUNCTION", "VIEW", "PROCEDURE"];

// Add/set standard parameters.
Args.Parameter(MigrationArgsBase.DatabaseNameParamName, _databaseName, true);
Args.Parameter(MigrationArgsBase.JournalSchemaParamName, null, true);
Args.Parameter(MigrationArgsBase.JournalTableParamName, "schemaversions");
Args.AddParameter(MigrationArgsBase.DatabaseNameParamName, _databaseName, true);
Args.AddParameter(MigrationArgsBase.JournalSchemaParamName, null, true);
Args.AddParameter(MigrationArgsBase.JournalTableParamName, "schemaversions");
}

/// <inheritdoc/>
Expand All @@ -69,7 +69,7 @@ public MySqlMigration(MigrationArgsBase args) : base(args)
public override IDatabase MasterDatabase => _masterDatabase;

/// <inheritdoc/>
public override DatabaseSchemaConfig DatabaseSchemaConfig => new MySqlSchemaConfig(DatabaseName);
public override DatabaseSchemaConfig SchemaConfig { get; }

/// <inheritdoc/>
protected override DatabaseSchemaScriptBase CreateSchemaScript(DatabaseMigrationScript migrationScript) => MySqlSchemaScript.Create(migrationScript);
Expand All @@ -78,7 +78,7 @@ public MySqlMigration(MigrationArgsBase args) : base(args)
protected override async Task<bool> DatabaseResetAsync(CancellationToken cancellationToken = default)
{
// Filter out the versioning table.
_resetBypass.Add($"`{Journal.Table}`");
_resetBypass.Add(SchemaConfig.ToFullyQualifiedTableName(Journal.Schema!, Journal.Table!));

// Carry on as they say ;-)
return await base.DatabaseResetAsync(cancellationToken).ConfigureAwait(false);
Expand Down
8 changes: 4 additions & 4 deletions src/DbEx.MySql/Migration/MySqlSchemaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static MySqlSchemaScript Create(DatabaseMigrationScript migrationScript)
/// <inheritdoc/>
public override string SqlCreateStatement => $"CREATE {Type.ToUpperInvariant()} `{Name}`";

private class SqlCommandTokenizer : SqlCommandReader
private class SqlCommandTokenizer(string sqlText) : SqlCommandReader(sqlText)
{
public SqlCommandTokenizer(string sqlText) : base(sqlText) { }
private readonly char[] delimiters = ['(', ')', ';', ',', '='];

public string[] ReadAllTokens()
{
Expand All @@ -81,7 +81,7 @@ public string[] ReadAllTokens()
sb.Clear();
break;
}
else if (new char[] { '(', ')', ';', ',', '=' }.Contains(c))
else if (delimiters.Contains(c))
{
if (sb.Length > 0)
words.Add(sb.ToString());
Expand Down Expand Up @@ -114,7 +114,7 @@ public string[] ReadAllTokens()
if (sb.Length > 0)
words.Add(sb.ToString());

return words.ToArray();
return [.. words];
}
}
}
Expand Down
Loading

0 comments on commit d727345

Please sign in to comment.