From 571617de9bff8d4a045c1857da97cc2ba787d5ef Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 3 Apr 2025 20:17:03 -0500 Subject: run migrations when non-volatile --- src/slskd/Program.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 068e62ae..690960a7 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -494,11 +494,10 @@ namespace slskd var app = builder.Build(); - var migrator = app.Services.GetService(); - - if (migrator is not null) + if (!OptionsAtStartup.Flags.Volatile) { - migrator.Migrate(force: OptionsAtStartup.Flags.ForceMigrations); + // note: if this ever throws, we've forgotten to register a Migrator following database DI config + app.Services.GetService().Migrate(force: OptionsAtStartup.Flags.ForceMigrations); } // hack: services that exist only to subscribe to the event bus are not referenced by anything else @@ -606,7 +605,9 @@ namespace slskd // we're working with non-volatile database files, so register a Migrator to be used later in the // bootup process. the presence of a Migrator instance in DI determines whether a migration is needed. - services.AddSingleton(_ => new Migrator()); + // it's important that we keep this list of databases in sync with those used by the application; anything + // not in this list will not be able to be migrated. + services.AddSingleton(_ => new Migrator(databases: ["search", "transfers", "messaging", "events"])); } services.AddSingleton(); -- cgit v1.2.3