adds updateDb command
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
This commit is contained in:
parent
551ef82c01
commit
d1290f73c1
44
PiwigoDirectorySync/Commands/UpdateDatabaseCommand.cs
Normal file
44
PiwigoDirectorySync/Commands/UpdateDatabaseCommand.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PiwigoDirectorySync.Infrastructure;
|
||||
using PiwigoDirectorySync.Persistence;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace PiwigoDirectorySync.Commands;
|
||||
|
||||
internal class UpdateDatabaseCommand : CancellableAsyncCommand<UpdateDatabaseCommand.UpdateDatabaseSettings>
|
||||
{
|
||||
private readonly ILogger<UpdateDatabaseCommand> _logger;
|
||||
private readonly PersistenceContext _persistenceContext;
|
||||
|
||||
public UpdateDatabaseCommand(ILogger<UpdateDatabaseCommand> logger, PersistenceContext persistenceContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_persistenceContext = persistenceContext;
|
||||
}
|
||||
|
||||
protected override async Task<int> ExecuteAsync(CommandContext context, UpdateDatabaseSettings settings, CancellationToken cancellation)
|
||||
{
|
||||
try
|
||||
{
|
||||
await AnsiConsole.Status()
|
||||
.Spinner(Spinner.Known.Star)
|
||||
.SpinnerStyle(Style.Parse("green bold"))
|
||||
.StartAsync("[orange3]Updating database[/]", async _ => { await _persistenceContext.Database.MigrateAsync(cancellation); });
|
||||
AnsiConsole.MarkupLine("[green]done[/]");
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical(ex, "Could not update database due to an error {ExMessage}", ex.Message);
|
||||
AnsiConsole.WriteException(ex);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
internal class UpdateDatabaseSettings : CommandSettings
|
||||
{
|
||||
}
|
||||
}
|
@ -59,6 +59,7 @@ app.Configure(config =>
|
||||
c.AddCommand<PiwigoUpdateCommand>("update");
|
||||
c.AddCommand<PiwigoRemoveCommand>("remove");
|
||||
});
|
||||
config.AddCommand<UpdateDatabaseCommand>("updateDb");
|
||||
});
|
||||
|
||||
return await app.RunAsync(args);
|
@ -42,6 +42,12 @@
|
||||
"commandLineArgs": "piwigo list",
|
||||
"environmentVariables": {
|
||||
}
|
||||
},
|
||||
"UpdateDb": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "updateDb",
|
||||
"environmentVariables": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user