Skip to content

Commit

Permalink
Update to .NET 8/9, replace System.Data.SqlClient
Browse files Browse the repository at this point in the history
Updated GitHub Actions workflows to use .NET Core 8.0.x and 9.0.x, removing support for .NET Core 6.0.x and 7.0.x. Replaced `System.Data.SqlClient` with `Microsoft.Data.SqlClient` across relevant files. Enhanced `MicrosoftSqlConnector` with a return statement post script execution and introduced `SqlTransaction` for better transaction handling. Cleaned up `DbMigrator.cs` by removing TODO comments for .NET 6, adding a new TODO for version 4.0.0 deployment, and managing CA1871 warnings. Removed redundant null checks in `DbMigrator` constructor. Updated project files to target .NET 8.0 and 9.0, and refreshed package references. Enhanced `SqlServerIntegrationTests` with connection string builder logic. Updated `README.md` to reflect these changes.
  • Loading branch information
Retrodad0001 committed Nov 22, 2024
1 parent 0b5795e commit de8a2c7
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 53 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/BuildRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@ jobs:
- name: Check out the Repository
uses: actions/checkout@v2

- name: Setup .NET Core 6.0.x LTS
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x

- name: Setup .NET Core 7.0.x
- name: Setup .NET Core 8.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Setup .NET Core 8.0.x
- name: Setup .NET Core 9.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Restore dependencies
run: dotnet restore
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/BuildTestDebug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@ jobs:
- name: Check out the Repository
uses: actions/checkout@v2

- name: Setup .NET Core 6.0.x LTS
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x

- name: Setup .NET Core 7.0.x
- name: Setup .NET Core 8.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Setup .NET Core 8.0.x
- name: Setup .NET Core 9.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Restore dependencies
run: dotnet restore
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/PackageAndReleaseMasterToNuGet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@ jobs:
- name: Check out Repo
uses: actions/checkout@v2

- name: Setup dotnet 6.x.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.x.x

- name: Setup .NET Core 7.x.x
- name: Setup .NET Core 8.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.x.x
dotnet-version: 8.0.x

- name: Setup .NET Core 8.0.x
- name: Setup .NET Core 9.0.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Pack
run: dotnet pack EasyDbMigrator\\EasyDbMigrator.csproj -c Release
Expand Down
4 changes: 3 additions & 1 deletion EasyDbMigrator/DatabaseConnectors/MicrosoftSqlConnector.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Ignore Spelling: Sql

using Microsoft.Data.SqlClient;
using Polly;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -43,6 +43,7 @@ ALTER DATABASE {migrationConfiguration.DatabaseName}
, scriptName: "EasyDbMigrator.Integrationtest_dropDatabase"
, sqlScriptContent: query
, cancellationToken: cancellationToken).ConfigureAwait(continueOnCapturedContext: false);

return result;
}

Expand Down Expand Up @@ -116,6 +117,7 @@ public async Task<Result<RunMigrationResult>> RunDbMigrationScriptAsync(Migratio
return new Result<RunMigrationResult>(wasSuccessful: true, value: RunMigrationResult.MigrationWasCancelled);
}


SqlTransaction? transaction = null;
try
{
Expand Down
17 changes: 5 additions & 12 deletions EasyDbMigrator/DbMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

namespace EasyDbMigrator;

//TODO remove .net 6 actions
//TODO add .net 9 actions
//TOOD add. net 9 target
//TOOD update packages

//TODO versie 4.0.0 and deploy new package

/// <summary>
/// The main class to run the migration scripts
Expand Down Expand Up @@ -43,25 +39,19 @@ public DbMigrator(ILogger logger
, IDirectoryHelper directoryHelper
, IDataTimeHelper dataTimeHelper)
{

ArgumentNullException.ThrowIfNull(argument: logger);

_logger = logger;

ArgumentNullException.ThrowIfNull(argument: databaseConnector);

_databaseConnector = databaseConnector;

ArgumentNullException.ThrowIfNull(argument: assemblyResourceHelper);

_assemblyResourceHelper = assemblyResourceHelper;

ArgumentNullException.ThrowIfNull(argument: directoryHelper);

_directoryHelper = directoryHelper;

ArgumentNullException.ThrowIfNull(argument: dataTimeHelper);

_dataTimeHelper = dataTimeHelper;
}

Expand All @@ -76,7 +66,9 @@ public static DbMigrator Create(MigrationConfiguration? migrationConfiguration
, ILogger logger
, IDatabaseConnector databaseConnector)
{
#pragma warning disable CA1871 // Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'
ArgumentNullException.ThrowIfNull(argument: migrationConfiguration);
#pragma warning restore CA1871 // Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'

ArgumentNullException.ThrowIfNull(argument: logger);

Expand Down Expand Up @@ -104,7 +96,9 @@ public static DbMigrator CreateForLocalIntegrationTesting(MigrationConfiguration
, IDataTimeHelper dataTimeHelperMock
, IDatabaseConnector databaseConnector)
{
#pragma warning disable CA1871 // Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'
ArgumentNullException.ThrowIfNull(argument: migrationConfiguration);
#pragma warning restore CA1871 // Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'

ArgumentNullException.ThrowIfNull(argument: logger);

Expand Down Expand Up @@ -132,7 +126,6 @@ public static DbMigrator CreateForLocalIntegrationTesting(MigrationConfiguration
public virtual async Task<bool> TryDeleteDatabaseIfExistAsync(MigrationConfiguration migrationConfiguration
, CancellationToken cancellationToken = default)
{

var succeeded = await _databaseConnector.TryDeleteDatabaseIfExistAsync(migrationConfiguration
, cancellationToken).ConfigureAwait(false);

Expand Down
10 changes: 5 additions & 5 deletions EasyDbMigrator/EasyDbMigrator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down Expand Up @@ -52,10 +52,10 @@ For help and release info see: https://github.com/Retrodad0001/EasyDbMigrator</P
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Npgsql" Version="8.0.4" />
<PackageReference Include="Polly" Version="8.4.2" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="Npgsql" Version="9.0.1" />
<PackageReference Include="Polly" Version="8.5.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
</ItemGroup>

Expand Down
10 changes: 5 additions & 5 deletions EasyDbMigratorTests/EasyDbMigratorTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>false</IsPackable>
<Nullable>annotations</Nullable>
Expand All @@ -17,11 +17,11 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Dapper" Version="2.1.44" />
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
<PackageReference Include="TestEnvironment.Docker.Containers.Mssql" Version="2.1.8" />
<PackageReference Include="TestEnvironment.Docker.Containers.Postgres" Version="2.1.6" />
<PackageReference Include="xunit" Version="2.9.2" />
Expand Down
19 changes: 19 additions & 0 deletions EasyDbMigratorTests/IntegrationTests/SqlServerIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ public async Task When_nothing_goes_wrong_with_running_the_migrations_on_an_empt
try
{
await dockerEnvironmentSql.UpAsync();

string connectionString = dockerEnvironmentSql.GetContainer<MssqlContainer>(DatabaseName)?.GetConnectionString();
System.Data.SqlClient.SqlConnectionStringBuilder builder = new(connectionString)
{
Encrypt = false,
TrustServerCertificate = true
};
connectionString = builder.ConnectionString;

MigrationConfiguration config = new(connectionString ?? throw new InvalidOperationException()
, DatabaseName);
Expand Down Expand Up @@ -107,6 +114,12 @@ public async Task Can_skip_scripts_if_they_already_run_before()
{
await dockerEnvironmentSql.UpAsync();
string connectionString = dockerEnvironmentSql.GetContainer<MssqlContainer>(DatabaseName)?.GetConnectionString();
System.Data.SqlClient.SqlConnectionStringBuilder builder = new(connectionString)
{
Encrypt = false,
TrustServerCertificate = true
};
connectionString = builder.ConnectionString;

MigrationConfiguration config = new(connectionString ?? throw new InvalidOperationException()
, DatabaseName);
Expand Down Expand Up @@ -200,6 +213,12 @@ public async Task Can_cancel_the_migration_process()
{
await dockerEnvironmentSql.UpAsync(token);
string connectionString = dockerEnvironmentSql.GetContainer<MssqlContainer>(DatabaseName)?.GetConnectionString();
System.Data.SqlClient.SqlConnectionStringBuilder builder = new(connectionString)
{
Encrypt = false,
TrustServerCertificate = true
};
connectionString = builder.ConnectionString;

MigrationConfiguration config = new(connectionString ?? throw new InvalidOperationException()
, DatabaseName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageProjectUrl>https://github.com/Retrodad0001/EasyDbMigrator</PackageProjectUrl>
<RepositoryUrl>https://github.com/Retrodad0001/EasyDbMigrator</RepositoryUrl>
Expand All @@ -28,4 +28,8 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageProjectUrl>https://github.com/Retrodad0001/EasyDbMigrator</PackageProjectUrl>
<RepositoryUrl>https://github.com/Retrodad0001/EasyDbMigrator</RepositoryUrl>
Expand All @@ -28,4 +28,8 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# The Latest news and Roadmap

## 4.0.x (the latest release)
- add support for .net 9 and removed the not supported .net versions

## 3.0.x (the latest release)
- add support for .net 8 and .NET 9 (when stable version is out)
- add support for .net 8 and
- monthly updates of all packages for stability and security

## 2.0.x
Expand Down

0 comments on commit de8a2c7

Please sign in to comment.