mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-03-27 00:31:44 +01:00
Order migrations
This commit is contained in:
parent
991a6c7713
commit
cec5a01d5d
@ -173,7 +173,7 @@ if (!string.IsNullOrEmpty(voidSettings.Postgres))
|
||||
if (voidSettings.HasRedis())
|
||||
{
|
||||
services.AddTransient<ICache, RedisCache>();
|
||||
|
||||
|
||||
// redis specific migrations
|
||||
services.AddTransient<IMigration, UserLookupKeyHashMigration>();
|
||||
}
|
||||
@ -190,7 +190,7 @@ using (var migrationScope = app.Services.CreateScope())
|
||||
{
|
||||
var migrations = migrationScope.ServiceProvider.GetServices<IMigration>();
|
||||
var logger = migrationScope.ServiceProvider.GetRequiredService<ILogger<IMigration>>();
|
||||
foreach (var migration in migrations)
|
||||
foreach (var migration in migrations.OrderBy(a => a.Order))
|
||||
{
|
||||
logger.LogInformation("Running migration: {Migration}", migration.GetType().Name);
|
||||
var res = await migration.Migrate(args);
|
||||
|
@ -3,6 +3,7 @@ using VoidCat.Services.Abstractions;
|
||||
|
||||
namespace VoidCat.Services.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class FixSize : IMigration
|
||||
{
|
||||
private readonly ILogger<FixSize> _logger;
|
||||
@ -16,6 +17,10 @@ public class FixSize : IMigration
|
||||
_fileStore = fileStore;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<IMigration.MigrationResult> Migrate(string[] args)
|
||||
{
|
||||
var files = await _fileMetadata.ListFiles<SecretVoidFileMeta>(new(0, int.MaxValue));
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace VoidCat.Services.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class FluentMigrationRunner : IMigration
|
||||
{
|
||||
private readonly IMigrationRunner _runner;
|
||||
@ -11,6 +12,10 @@ public class FluentMigrationRunner : IMigration
|
||||
_runner = runner;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => -1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ValueTask<IMigration.MigrationResult> Migrate(string[] args)
|
||||
{
|
||||
_runner.MigrateUp();
|
||||
|
@ -1,9 +1,25 @@
|
||||
namespace VoidCat.Services.Migrations;
|
||||
|
||||
/// <summary>
|
||||
/// Startup migrations
|
||||
/// </summary>
|
||||
public interface IMigration
|
||||
{
|
||||
/// <summary>
|
||||
/// Order to run migrations
|
||||
/// </summary>
|
||||
int Order { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Run migration
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
ValueTask<MigrationResult> Migrate(string[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Results of running migration
|
||||
/// </summary>
|
||||
public enum MigrationResult
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -3,6 +3,7 @@ using VoidCat.Model;
|
||||
|
||||
namespace VoidCat.Services.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract class MetadataMigrator<TOld, TNew> : IMigration
|
||||
{
|
||||
private readonly VoidSettings _settings;
|
||||
@ -14,6 +15,10 @@ public abstract class MetadataMigrator<TOld, TNew> : IMigration
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<IMigration.MigrationResult> Migrate(string[] args)
|
||||
{
|
||||
var newMeta = Path.Combine(_settings.DataDirectory, OldPath);
|
||||
|
@ -34,6 +34,9 @@ public class MigrateToPostgres : IMigration
|
||||
_fileStore = fileStore;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => 0;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<IMigration.MigrationResult> Migrate(string[] args)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using VoidCat.Services.Abstractions;
|
||||
|
||||
namespace VoidCat.Services.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class PopulateMetadataId : IMigration
|
||||
{
|
||||
private readonly IFileMetadataStore _metadataStore;
|
||||
@ -12,6 +13,10 @@ public class PopulateMetadataId : IMigration
|
||||
_metadataStore = metadataStore;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<IMigration.MigrationResult> Migrate(string[] args)
|
||||
{
|
||||
if (!args.Contains("--add-metadata-id"))
|
||||
|
@ -4,6 +4,7 @@ using VoidCat.Model;
|
||||
|
||||
namespace VoidCat.Services.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class UserLookupKeyHashMigration : IMigration
|
||||
{
|
||||
private readonly IDatabase _database;
|
||||
@ -13,6 +14,10 @@ public class UserLookupKeyHashMigration : IMigration
|
||||
_database = database;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<IMigration.MigrationResult> Migrate(string[] args)
|
||||
{
|
||||
var users = await _database.SetMembersAsync("users");
|
||||
|
Loading…
x
Reference in New Issue
Block a user