| | | 1 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Relational.Contracts; |
| | | 2 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Relational.Migrations; |
| | | 3 | | using Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Options; |
| | | 4 | | using FluentMigrator.Runner; |
| | | 5 | | using Microsoft.Extensions.DependencyInjection; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Services; |
| | | 9 | | |
| | 20 | 10 | | public class SqliteStructuredLogSchemaMigrator(IOptions<SqliteStructuredLogOptions> options) : IStructuredLogSchemaMigra |
| | | 11 | | { |
| | | 12 | | public ValueTask MigrateAsync(CancellationToken cancellationToken = default) |
| | | 13 | | { |
| | 18 | 14 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 15 | | |
| | 18 | 16 | | using var services = new ServiceCollection() |
| | 18 | 17 | | .AddLogging() |
| | 18 | 18 | | .AddFluentMigratorCore() |
| | 18 | 19 | | .ConfigureRunner(builder => builder |
| | 18 | 20 | | .AddSQLite() |
| | 18 | 21 | | .WithGlobalConnectionString(options.Value.ConnectionString) |
| | 18 | 22 | | .ScanIn(typeof(M001CreateStructuredLogTables).Assembly).For.Migrations()) |
| | 18 | 23 | | .BuildServiceProvider(false); |
| | | 24 | | |
| | 18 | 25 | | using var scope = services.CreateScope(); |
| | 18 | 26 | | scope.ServiceProvider.GetRequiredService<IMigrationRunner>().MigrateUp(); |
| | 18 | 27 | | return ValueTask.CompletedTask; |
| | 18 | 28 | | } |
| | | 29 | | } |