Skip to content

Commit 6616301

Browse files
Migration can be launched when the identity server is started
1 parent 00c279b commit 6616301

5 files changed

Lines changed: 465 additions & 306 deletions

File tree

src/IdServer/SimpleIdServer.IdServer.Migrations/IdServerBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public static IdServerBuilder EnableMigration(this IdServerBuilder idserverBuild
1313
{
1414
idserverBuilder.Services.AddTransient<IMigrationServiceFactory, MigrationServiceFactory>();
1515
idserverBuilder.Services.AddTransient<IDataSeeder, AddMigrationsScopeDataSeeder>();
16+
idserverBuilder.Services.AddTransient<ILaunchMigrationService, LaunchMigrationService>();
17+
idserverBuilder.Services.AddTransient<ILaunchAllMigrationsService, LaunchAllMigrationsService>();
1618
idserverBuilder.AddRoute("getAllDefsMigrations", Constants.Endpoints.MigDefinitions, new { controller = "Migrations", action = "GetAllDefinitions" });
1719
idserverBuilder.AddRoute("getAllExecutionsMigrations", Constants.Endpoints.MigExecutions, new { controller = "Migrations", action = "GetAllExecutions" });
1820
idserverBuilder.AddRoute("launchMigration", Constants.Endpoints.LaunchMigration, new { controller = "Migrations", action = "Launch" });
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace SimpleIdServer.IdServer.Migrations;
5+
6+
public interface ILaunchAllMigrationsService
7+
{
8+
Task LaunchAll(string realm, CancellationToken cancellationToken);
9+
}
10+
11+
public class LaunchAllMigrationsService : ILaunchAllMigrationsService
12+
{
13+
private readonly IEnumerable<IMigrationService> _migrationServices;
14+
private readonly ILaunchMigrationService _launchMigrationService;
15+
16+
public LaunchAllMigrationsService(IEnumerable<IMigrationService> migrationServices, ILaunchMigrationService launchMigrationService)
17+
{
18+
_migrationServices = migrationServices;
19+
_launchMigrationService = launchMigrationService;
20+
}
21+
22+
public async Task LaunchAll(string realm, CancellationToken cancellationToken)
23+
{
24+
var names = _migrationServices.Select(m => m.Name);
25+
foreach(var name in names)
26+
{
27+
await _launchMigrationService.Launch(realm, name, cancellationToken);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)