mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2024-11-23 10:42:51 +01:00
26 lines
823 B
C#
26 lines
823 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Phantom.Utils.Logging;
|
|
using Phantom.Utils.Tasks;
|
|
using Serilog;
|
|
|
|
namespace Phantom.Controller.Database;
|
|
|
|
public static class DatabaseMigrator {
|
|
private static readonly ILogger Logger = PhantomLogger.Create(nameof(DatabaseMigrator));
|
|
|
|
public static async Task Run(IDbContextProvider dbProvider, CancellationToken cancellationToken) {
|
|
await using var ctx = dbProvider.Eager();
|
|
|
|
Logger.Information("Connecting to database...");
|
|
|
|
var retryConnection = new Throttler(TimeSpan.FromSeconds(10));
|
|
while (!await ctx.Database.CanConnectAsync(cancellationToken)) {
|
|
Logger.Warning("Cannot connect to database, retrying...");
|
|
await retryConnection.Wait();
|
|
}
|
|
|
|
Logger.Information("Running migrations...");
|
|
await ctx.Database.MigrateAsync(CancellationToken.None);
|
|
}
|
|
}
|