diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..a4478dc
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,25 @@
+name: .NET
+
+on:
+ push:
+ branches: [ '**' ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v6
+
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v5
+ with:
+ dotnet-version: '10.0.x'
+
+ - name: Restore
+ run: dotnet restore
+
+ - name: Build
+ run: dotnet build --no-restore -c Release
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
deleted file mode 100644
index a44c418..0000000
--- a/.github/workflows/dotnet.yml
+++ /dev/null
@@ -1,33 +0,0 @@
-name: .NET
-
-on:
- push:
- branches: [ '**' ]
-
-jobs:
- build:
-
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v4
-
- - name: Setup .NET
- uses: actions/setup-dotnet@v3
- with:
- dotnet-version: '8.0.x'
-
- - name: Add Garage Group NuGet Source
- run: >
- dotnet nuget add source ${{ vars.GG_NUGET_SOURCE_URL }}
- -n garage
- -u ${{ secrets.GG_NUGET_SOURCE_USER_NAME }}
- -p ${{ secrets.GG_NUGET_SOURCE_USER_PASSWORD }}
- --store-password-in-clear-text
-
- - name: Restore Console
- run: dotnet restore ./src/*/Console.csproj
-
- - name: Build Console
- run: dotnet build ./src/*/Console.csproj --no-restore -c Release
diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index 23120ee..8e7c81e 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -20,33 +20,25 @@ jobs:
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Setup .NET
- uses: actions/setup-dotnet@v3
+ uses: actions/setup-dotnet@v5
with:
- dotnet-version: '8.0.x'
+ dotnet-version: '10.0.x'
- name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v2
-
- - name: Add Garage Group NuGet Source
- run: >
- dotnet nuget add source ${{ vars.GG_NUGET_SOURCE_URL }}
- -n garage
- -u ${{ secrets.GG_NUGET_SOURCE_USER_NAME }}
- -p ${{ secrets.GG_NUGET_SOURCE_USER_PASSWORD }}
- --store-password-in-clear-text
+ uses: docker/setup-buildx-action@v4
- name: Publish Console.csproj
run: dotnet publish ./src/*/Console.csproj -c Release -o './publish'
- name: Login to Github Packages
- uses: docker/login-action@v2
+ uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image and push to GitHub Container Registry
- uses: docker/build-push-action@v4
+ uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
@@ -54,6 +46,3 @@ jobs:
ghcr.io/garagegroup/gg-sql-migration:${{ steps.vars.outputs.tag }}
ghcr.io/garagegroup/gg-sql-migration:latest
push: true
-
- - name: Image digest
- run: echo ${{ steps.docker_build.outputs.digest }}
diff --git a/Dockerfile b/Dockerfile
index 872c75b..594385d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM mcr.microsoft.com/dotnet/runtime:8.0
+FROM mcr.microsoft.com/dotnet/runtime:10.0
WORKDIR /app
COPY ./publish ./
diff --git a/Infra.Sql.Migration.slnx b/Infra.Sql.Migration.slnx
new file mode 100644
index 0000000..1e3d8d1
--- /dev/null
+++ b/Infra.Sql.Migration.slnx
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Console/Application.cs b/src/Console/Application.cs
new file mode 100644
index 0000000..d264755
--- /dev/null
+++ b/src/Console/Application.cs
@@ -0,0 +1,27 @@
+using System;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using PrimeFuncPack;
+
+namespace GarageGroup.Infra;
+
+internal static class Application
+{
+ public static Dependency UseSqlMigrateHandler()
+ =>
+ MicrosoftDbProvider.Configure("SqlDb")
+ .UseSqlApi()
+ .With(ResolveSqlMigrationOption)
+ .UseSqlMigrateHandler();
+
+ private static SqlMigrationOption ResolveSqlMigrationOption(IServiceProvider serviceProvider)
+ {
+ var section = serviceProvider.GetRequiredService().GetRequiredSection("Migrations");
+
+ return new(
+ configPath: section["ConfigPath"])
+ {
+ BasePath = section["BasePath"]
+ };
+ }
+}
\ No newline at end of file
diff --git a/src/Console/Console.csproj b/src/Console/Console.csproj
index e0b5b43..dcc1c0f 100644
--- a/src/Console/Console.csproj
+++ b/src/Console/Console.csproj
@@ -1,12 +1,13 @@
- net8.0
+ net10.0
Exe
disable
enable
false
true
+ $(NoWarn);IDE0130;CA1859
GarageGroup.Infra
GarageGroup.Infra.Sql.Migration.Console
@@ -20,9 +21,9 @@
-
-
-
+
+
+
-
+
\ No newline at end of file
diff --git a/src/Console/Program.cs b/src/Console/Program.cs
index af8b585..033e3cd 100644
--- a/src/Console/Program.cs
+++ b/src/Console/Program.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
namespace GarageGroup.Infra.Sql.Migration.Console;
@@ -7,8 +6,5 @@ static class Program
{
static Task Main(string[] args)
=>
- MicrosoftDbProvider.Configure("SqlDb")
- .UseSqlApi()
- .UseSqlMigrateHandler("Migrations")
- .RunConsoleAsync(default, args);
+ Application.UseSqlMigrateHandler().UseConsoleRunner(args).RunAsync();
}
\ No newline at end of file
diff --git a/src/Handler/Handler.Contract/ISqlMigrateHandler.cs b/src/Handler/Handler.Contract/ISqlMigrateHandler.cs
new file mode 100644
index 0000000..8ec808e
--- /dev/null
+++ b/src/Handler/Handler.Contract/ISqlMigrateHandler.cs
@@ -0,0 +1,5 @@
+using System;
+
+namespace GarageGroup.Infra;
+
+public interface ISqlMigrateHandler : IHandler;
\ No newline at end of file
diff --git a/src/Handler/Handler.csproj b/src/Handler/Handler.csproj
index d6203c4..5c575a5 100644
--- a/src/Handler/Handler.csproj
+++ b/src/Handler/Handler.csproj
@@ -1,23 +1,23 @@
- net8.0
+ net10.0
disable
enable
true
true
+ $(NoWarn);IDE0130;CA1859
GarageGroup.Infra
GarageGroup.Infra.Sql.Migration.Handler
-
-
-
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Handler/SqlMigrateHandler/Handler.Handle.cs b/src/Handler/Handler/Handler.Handle.cs
similarity index 62%
rename from src/Handler/SqlMigrateHandler/Handler.Handle.cs
rename to src/Handler/Handler/Handler.Handle.cs
index 467a94b..1b629e0 100644
--- a/src/Handler/SqlMigrateHandler/Handler.Handle.cs
+++ b/src/Handler/Handler/Handler.Handle.cs
@@ -7,38 +7,28 @@ namespace GarageGroup.Infra;
partial class SqlMigrateHandler
{
- public ValueTask>> HandleAsync(Unit _, CancellationToken cancellationToken)
+ public async ValueTask>> HandleAsync(Unit unit, CancellationToken cancellationToken)
{
- if (cancellationToken.IsCancellationRequested)
- {
- return ValueTask.FromCanceled>>(cancellationToken);
- }
-
- return InnerHandleAsync(cancellationToken);
- }
-
- private async ValueTask>> InnerHandleAsync(CancellationToken cancellationToken)
- {
- logger.LogInformation("Check if the change log table exists");
+ logger.LogInformation("Check if the change log table exists.");
await changeLogApi.EnsureTableAsync(cancellationToken).ConfigureAwait(false);
- logger.LogInformation("Get the last change log from the database");
+ logger.LogInformation("Get the last change log from the database.");
var dbChangeLogId = await changeLogApi.GetLastChangeLogIdAsync(cancellationToken).ConfigureAwait(false);
var notExecutedMigrations = await migrationItemApi.GetMigrationItemsAsync(dbChangeLogId?.Id, cancellationToken).ConfigureAwait(false);
if (notExecutedMigrations.IsEmpty)
{
- logger.LogInformation("All migrations were already applied");
- return Result.Success(default);
+ logger.LogInformation("All migrations were already applied.");
+ return Result.Success(unit);
}
foreach (var migration in notExecutedMigrations)
{
- logger.LogInformation("Apply the migration {migrationId}", migration.Id);
+ logger.LogInformation("Apply the migration {migrationId}.", migration.Id);
await changeLogApi.ExecuteMigrationQueryAsync(migration, cancellationToken).ConfigureAwait(false);
}
- logger.LogInformation("All migrations have been applied successfully");
- return Result.Success(default);
+ logger.LogInformation("All migrations have been applied successfully.");
+ return Result.Success(unit);
}
}
\ No newline at end of file
diff --git a/src/Handler/SqlMigrateHandler/SqlMigrateHandler.cs b/src/Handler/Handler/SqlMigrateHandler.cs
similarity index 90%
rename from src/Handler/SqlMigrateHandler/SqlMigrateHandler.cs
rename to src/Handler/Handler/SqlMigrateHandler.cs
index 19bc0cf..ba8c23e 100644
--- a/src/Handler/SqlMigrateHandler/SqlMigrateHandler.cs
+++ b/src/Handler/Handler/SqlMigrateHandler.cs
@@ -1,9 +1,8 @@
-using System;
using Microsoft.Extensions.Logging;
namespace GarageGroup.Infra;
-public sealed partial class SqlMigrateHandler : IHandler
+internal sealed partial class SqlMigrateHandler : ISqlMigrateHandler
{
internal static SqlMigrateHandler InternalCreate(
IDbChangeLogApi changeLogApi, ISqlMigrationItemApi migrationItemApi, ILoggerFactory loggerFactory)
diff --git a/src/Handler/Internal.DbChangeLog/Api/Api.EnsureTable.cs b/src/Handler/Internal.DbChangeLog/Api/Api.EnsureTable.cs
index 1f7955c..2b79377 100644
--- a/src/Handler/Internal.DbChangeLog/Api/Api.EnsureTable.cs
+++ b/src/Handler/Internal.DbChangeLog/Api/Api.EnsureTable.cs
@@ -5,13 +5,7 @@ namespace GarageGroup.Infra;
partial class DbChangeLogApi
{
- public async ValueTask EnsureTableAsync(CancellationToken cancellationToken)
- {
- var query = new DbQuery(DbChangeLogCreateTableQuery)
- {
- TimeoutInSeconds = DbTimeoutInSeconds
- };
-
- _ = await sqlApi.ExecuteNonQueryAsync(query, cancellationToken).ConfigureAwait(false);
- }
+ public Task EnsureTableAsync(CancellationToken cancellationToken)
+ =>
+ sqlApi.ExecuteNonQueryAsync(DbChangeLogCreateTableQuery, cancellationToken).AsTask();
}
\ No newline at end of file
diff --git a/src/Handler/Internal.DbChangeLog/Api/Api.ExecuteMigrationQuery.cs b/src/Handler/Internal.DbChangeLog/Api/Api.ExecuteMigrationQuery.cs
index 07f29a4..686476f 100644
--- a/src/Handler/Internal.DbChangeLog/Api/Api.ExecuteMigrationQuery.cs
+++ b/src/Handler/Internal.DbChangeLog/Api/Api.ExecuteMigrationQuery.cs
@@ -1,4 +1,3 @@
-using System;
using System.Threading;
using System.Threading.Tasks;
@@ -6,7 +5,7 @@ namespace GarageGroup.Infra;
partial class DbChangeLogApi
{
- public async ValueTask ExecuteMigrationQueryAsync(SqlMigrationItem migrationItem, CancellationToken cancellationToken)
+ public async Task ExecuteMigrationQueryAsync(SqlMigrationItem migrationItem, CancellationToken cancellationToken)
{
var migrationQuery = await ReadMigrationQueryAsync(migrationItem, cancellationToken).ConfigureAwait(false);
@@ -17,11 +16,9 @@ public async ValueTask ExecuteMigrationQueryAsync(SqlMigrationItem migrationItem
_ = await sqlApi.ExecuteNonQueryAsync(migrationRequest, cancellationToken).ConfigureAwait(false);
- var logInsertRequest = new DbQuery(
- query: DbChangeLogInsertQuery,
- parameters: new(
- new("Id", migrationItem.Id),
- new("Comment", migrationItem.Comment.OrEmpty())))
+ var logInsertRequest = new DbChangeLogInsertQuery(
+ migrationId: migrationItem.Id,
+ comment: migrationItem.Comment)
{
TimeoutInSeconds = DbTimeoutInSeconds
};
@@ -29,13 +26,13 @@ public async ValueTask ExecuteMigrationQueryAsync(SqlMigrationItem migrationItem
_ = await sqlApi.ExecuteNonQueryAsync(logInsertRequest, cancellationToken).ConfigureAwait(false);
}
- private ValueTask ReadMigrationQueryAsync(SqlMigrationItem migrationItem, CancellationToken cancellationToken)
+ private Task ReadMigrationQueryAsync(SqlMigrationItem migrationItem, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(migrationItem.FilePath))
{
- return new(string.Empty);
+ return Task.FromResult(string.Empty);
}
- return new(fileReader.ReadAsync(option.BasePath, migrationItem.FilePath, cancellationToken));
+ return fileReader.ReadAsync(option.BasePath, migrationItem.FilePath, cancellationToken);
}
}
\ No newline at end of file
diff --git a/src/Handler/Internal.DbChangeLog/Api/Api.GetLastChangeLogId.cs b/src/Handler/Internal.DbChangeLog/Api/Api.GetLastChangeLogId.cs
index 4270729..5888690 100644
--- a/src/Handler/Internal.DbChangeLog/Api/Api.GetLastChangeLogId.cs
+++ b/src/Handler/Internal.DbChangeLog/Api/Api.GetLastChangeLogId.cs
@@ -6,14 +6,9 @@ namespace GarageGroup.Infra;
partial class DbChangeLogApi
{
- public async ValueTask GetLastChangeLogIdAsync(CancellationToken cancellationToken)
+ public async Task GetLastChangeLogIdAsync(CancellationToken cancellationToken)
{
- var sqlRequest = new DbQuery(DbChangeLogIdLastGetQuery)
- {
- TimeoutInSeconds = DbTimeoutInSeconds
- };
-
- var dbResult = await sqlApi.QueryEntityOrAbsentAsync(sqlRequest, cancellationToken).ConfigureAwait(false);
+ var dbResult = await sqlApi.QueryEntityOrAbsentAsync(DbChangeLogIdLastGetQuery, cancellationToken).ConfigureAwait(false);
return dbResult.Fold(AsNullable, GetNull);
static DbChangeLogId? AsNullable(DbChangeLogId dbChangeLogId)
diff --git a/src/Handler/Internal.DbChangeLog/Api/DbChangeLogApi.cs b/src/Handler/Internal.DbChangeLog/Api/DbChangeLogApi.cs
index cf4efa3..b7f7122 100644
--- a/src/Handler/Internal.DbChangeLog/Api/DbChangeLogApi.cs
+++ b/src/Handler/Internal.DbChangeLog/Api/DbChangeLogApi.cs
@@ -4,22 +4,19 @@ internal sealed partial class DbChangeLogApi : IDbChangeLogApi
{
private const int DbTimeoutInSeconds = int.MaxValue;
- private const string DbChangeLogCreateTableQuery = """
- IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='_ChangeLogHistory' and xtype='U')
- BEGIN
- CREATE TABLE [_ChangeLogHistory](
- [Id] varchar(100) NOT NULL,
- [Comment] nvarchar (255) NULL,
- [CreationTime] datetimeoffset NOT NULL DEFAULT SYSDATETIMEOFFSET(),
- PRIMARY KEY (Id)
- );
- CREATE INDEX ChangeLogHistoryCreationTimeIndex ON [_ChangeLogHistory](CreationTime DESC);
- END
- """;
-
- private const string DbChangeLogIdLastGetQuery = "SELECT TOP 1 Id From [_ChangeLogHistory] ORDER BY CreationTime DESC;";
-
- private const string DbChangeLogInsertQuery = "INSERT INTO [_ChangeLogHistory](Id, Comment) VALUES (@Id, @Comment);";
+ private static readonly DbChangeLogCreateTableQuery DbChangeLogCreateTableQuery
+ =
+ new()
+ {
+ TimeoutInSeconds = DbTimeoutInSeconds
+ };
+
+ private static readonly DbChangeLogIdLastGetQuery DbChangeLogIdLastGetQuery
+ =
+ new()
+ {
+ TimeoutInSeconds = DbTimeoutInSeconds
+ };
private readonly ISqlApi sqlApi;
diff --git a/src/Handler/Internal.DbChangeLog/Contract/IDbChangeLogApi.cs b/src/Handler/Internal.DbChangeLog/Contract/IDbChangeLogApi.cs
index cd39d59..e9142af 100644
--- a/src/Handler/Internal.DbChangeLog/Contract/IDbChangeLogApi.cs
+++ b/src/Handler/Internal.DbChangeLog/Contract/IDbChangeLogApi.cs
@@ -5,9 +5,9 @@ namespace GarageGroup.Infra;
internal interface IDbChangeLogApi
{
- ValueTask EnsureTableAsync(CancellationToken cancellationToken);
+ Task EnsureTableAsync(CancellationToken cancellationToken);
- ValueTask GetLastChangeLogIdAsync(CancellationToken cancellationToken);
+ Task GetLastChangeLogIdAsync(CancellationToken cancellationToken);
- ValueTask ExecuteMigrationQueryAsync(SqlMigrationItem migrationItem, CancellationToken cancellationToken);
+ Task ExecuteMigrationQueryAsync(SqlMigrationItem migrationItem, CancellationToken cancellationToken);
}
\ No newline at end of file
diff --git a/src/Handler/Internal.DbQuery/DbChangeLogCreateTableQuery.cs b/src/Handler/Internal.DbQuery/DbChangeLogCreateTableQuery.cs
new file mode 100644
index 0000000..6ab0eb7
--- /dev/null
+++ b/src/Handler/Internal.DbQuery/DbChangeLogCreateTableQuery.cs
@@ -0,0 +1,37 @@
+using System;
+
+namespace GarageGroup.Infra;
+
+internal sealed record class DbChangeLogCreateTableQuery : IDbQuery
+{
+ private const string TransactSqlQuery
+ =
+ """
+ IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='_ChangeLogHistory' and xtype='U')
+ BEGIN
+ CREATE TABLE [_ChangeLogHistory](
+ [Id] varchar(100) NOT NULL,
+ [Comment] nvarchar (255) NULL,
+ [CreationTime] datetimeoffset NOT NULL DEFAULT SYSDATETIMEOFFSET(),
+ PRIMARY KEY (Id)
+ );
+ CREATE INDEX ChangeLogHistoryCreationTimeIndex ON [_ChangeLogHistory](CreationTime DESC);
+ END
+ """;
+
+ public int? TimeoutInSeconds { get; init; }
+
+ public string GetSqlQuery(SqlDialect dialect)
+ {
+ if (dialect is SqlDialect.TransactSql)
+ {
+ return TransactSqlQuery;
+ }
+
+ throw new NotSupportedException($"Dialect '{dialect}' is not supported for {nameof(DbChangeLogCreateTableQuery)}.");
+ }
+
+ public FlatArray GetParameters()
+ =>
+ default;
+}
\ No newline at end of file
diff --git a/src/Handler/Internal.DbQuery/DbChangeLogIdLastGetQuery.cs b/src/Handler/Internal.DbQuery/DbChangeLogIdLastGetQuery.cs
new file mode 100644
index 0000000..fdfbe38
--- /dev/null
+++ b/src/Handler/Internal.DbQuery/DbChangeLogIdLastGetQuery.cs
@@ -0,0 +1,26 @@
+using System;
+
+namespace GarageGroup.Infra;
+
+internal sealed record class DbChangeLogIdLastGetQuery : IDbQuery
+{
+ private const string TransactSqlQuery
+ =
+ "SELECT TOP 1 Id From [_ChangeLogHistory] ORDER BY CreationTime DESC;";
+
+ public int? TimeoutInSeconds { get; init; }
+
+ public string GetSqlQuery(SqlDialect dialect)
+ {
+ if (dialect is SqlDialect.TransactSql)
+ {
+ return TransactSqlQuery;
+ }
+
+ throw new NotSupportedException($"Dialect '{dialect}' is not supported for {nameof(DbChangeLogIdLastGetQuery)}.");
+ }
+
+ public FlatArray GetParameters()
+ =>
+ default;
+}
\ No newline at end of file
diff --git a/src/Handler/Internal.DbQuery/DbChangeLogInsertQuery.cs b/src/Handler/Internal.DbQuery/DbChangeLogInsertQuery.cs
new file mode 100644
index 0000000..1d55c3a
--- /dev/null
+++ b/src/Handler/Internal.DbQuery/DbChangeLogInsertQuery.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Diagnostics.CodeAnalysis;
+
+namespace GarageGroup.Infra;
+
+internal sealed record class DbChangeLogInsertQuery : IDbQuery
+{
+ private const string TransactSqlQuery
+ =
+ "INSERT INTO [_ChangeLogHistory](Id, Comment) VALUES (@Id, @Comment);";
+
+ private readonly string migrationId;
+
+ private readonly string comment;
+
+ public DbChangeLogInsertQuery(string migrationId, [AllowNull] string comment)
+ {
+ this.migrationId = migrationId.OrEmpty();
+ this.comment = comment.OrEmpty();
+ }
+
+ public int? TimeoutInSeconds { get; init; }
+
+ public string GetSqlQuery(SqlDialect dialect)
+ {
+ if (dialect is SqlDialect.TransactSql)
+ {
+ return TransactSqlQuery;
+ }
+
+ throw new NotSupportedException($"Dialect '{dialect}' is not supported for {nameof(DbChangeLogInsertQuery)}.");
+ }
+
+ public FlatArray GetParameters()
+ =>
+ [
+ new("Id", migrationId),
+ new("Comment", comment)
+ ];
+}
\ No newline at end of file
diff --git a/src/Handler/Option/SqlMigrationOption.cs b/src/Handler/Option/SqlMigrationOption.cs
index 39bdd1c..9bb7836 100644
--- a/src/Handler/Option/SqlMigrationOption.cs
+++ b/src/Handler/Option/SqlMigrationOption.cs
@@ -2,19 +2,15 @@
namespace GarageGroup.Infra;
-public readonly record struct SqlMigrationOption
+public sealed record class SqlMigrationOption
{
private const string DefaultConfigPath = "migration.yaml";
- private readonly string? configPath;
-
public SqlMigrationOption([AllowNull] string configPath = DefaultConfigPath)
=>
- this.configPath = string.IsNullOrEmpty(configPath) ? null : configPath;
+ ConfigPath = string.IsNullOrWhiteSpace(configPath) ? DefaultConfigPath : configPath;
- public string ConfigPath
- =>
- string.IsNullOrEmpty(configPath) ? DefaultConfigPath : configPath;
+ public string ConfigPath { get; }
public string? BasePath { get; init; }
}
\ No newline at end of file
diff --git a/src/Handler/SqlMigrateHandlerDependency.cs b/src/Handler/SqlMigrateHandlerDependency.cs
index e23b710..8954866 100644
--- a/src/Handler/SqlMigrateHandlerDependency.cs
+++ b/src/Handler/SqlMigrateHandlerDependency.cs
@@ -1,5 +1,4 @@
using System;
-using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using PrimeFuncPack;
@@ -7,38 +6,22 @@ namespace GarageGroup.Infra;
public static class SqlMigrateHandlerDependency
{
- private const string DefaultConfigSection = "Migrations";
-
- public static Dependency UseSqlMigrateHandler(
- this Dependency dependency, string configSectionName = DefaultConfigSection)
+ public static Dependency UseSqlMigrateHandler(this Dependency dependency)
{
ArgumentNullException.ThrowIfNull(dependency);
- return dependency.Map(CreateHandler);
+ return dependency.Fold(CreateHandler);
- SqlMigrateHandler CreateHandler(IServiceProvider serviceProvider, ISqlApi sqlApi)
+ static SqlMigrateHandler CreateHandler(IServiceProvider serviceProvider, ISqlApi sqlApi, SqlMigrationOption option)
{
ArgumentNullException.ThrowIfNull(serviceProvider);
ArgumentNullException.ThrowIfNull(sqlApi);
-
- var option = serviceProvider.GetServiceOrThrow().GetRequiredSection(configSectionName).GetSqlMigrationOption();
+ ArgumentNullException.ThrowIfNull(option);
return SqlMigrateHandler.InternalCreate(
changeLogApi: new DbChangeLogApi(sqlApi, MigrationFileReader.Instance, option),
migrationItemApi: new SqlMigrationItemApi(MigrationFileReader.Instance, option),
- loggerFactory: serviceProvider.ResolveLoggerFactory());
+ loggerFactory: serviceProvider.GetServiceOrThrow());
}
}
-
- private static ILoggerFactory ResolveLoggerFactory(this IServiceProvider serviceProvider)
- =>
- serviceProvider.GetServiceOrThrow();
-
- private static SqlMigrationOption GetSqlMigrationOption(this IConfigurationSection section)
- =>
- new(
- configPath: section["ConfigPath"])
- {
- BasePath = section["BasePath"]
- };
}
\ No newline at end of file
diff --git a/src/Infra.Sql.Migration.sln b/src/Infra.Sql.Migration.sln
deleted file mode 100644
index cd35fd4..0000000
--- a/src/Infra.Sql.Migration.sln
+++ /dev/null
@@ -1,31 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 17
-VisualStudioVersion = 17.5.002.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Handler", "Handler\Handler.csproj", "{3BF44342-ACF8-43B8-92E5-9B788CF022BD}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console", "Console\Console.csproj", "{6AEC8188-1D74-460A-9713-FE6FC0879DB7}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {3BF44342-ACF8-43B8-92E5-9B788CF022BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {3BF44342-ACF8-43B8-92E5-9B788CF022BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {3BF44342-ACF8-43B8-92E5-9B788CF022BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {3BF44342-ACF8-43B8-92E5-9B788CF022BD}.Release|Any CPU.Build.0 = Release|Any CPU
- {6AEC8188-1D74-460A-9713-FE6FC0879DB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {6AEC8188-1D74-460A-9713-FE6FC0879DB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {6AEC8188-1D74-460A-9713-FE6FC0879DB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {6AEC8188-1D74-460A-9713-FE6FC0879DB7}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {B7F79146-B475-42FB-928C-EAFF5E56F251}
- EndGlobalSection
-EndGlobal