aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Data/Migrator.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-05-11 09:10:37 -0500
committerJP Dillingham <jp@dillingham.me>2025-05-11 09:14:49 -0500
commit9d2050a21996df047e20ca4a5da5da346d560008 (patch)
tree1e50ee96796d4900159e2442517a0aa202c61bb4 /src/slskd/Core/Data/Migrator.cs
parent3fed167896a1376bedf9f5997887674bc1b1e2ea (diff)
downloadslskd-9d2050a21996df047e20ca4a5da5da346d560008.tar.gz
final tweaks?
Diffstat (limited to 'src/slskd/Core/Data/Migrator.cs')
-rw-r--r--src/slskd/Core/Data/Migrator.cs24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/slskd/Core/Data/Migrator.cs b/src/slskd/Core/Data/Migrator.cs
index 9f28d747..02b65c0c 100644
--- a/src/slskd/Core/Data/Migrator.cs
+++ b/src/slskd/Core/Data/Migrator.cs
@@ -33,6 +33,9 @@ public interface IMigration
/// <summary>
/// Determines whether the migration needs to be applied.
/// </summary>
+ /// <remarks>
+ /// This method MUST be read-only and should contain no side effects.
+ /// </remarks>
/// <returns>A value indicating whether the migration needs to be applied.</returns>
bool NeedsToBeApplied();
@@ -56,13 +59,6 @@ public class Migrator
Databases = databases;
}
- private enum MigrationDisposition
- {
- AlreadyAppliedPerHistoryFile,
- ApplicationNotNeededPerMigration,
- ApplicationRequired,
- }
-
private string HistoryFileName { get; } = Path.Combine(Program.DataMigrationsDirectory, "history");
private IEnumerable<string> Databases { get; }
private ILogger Log { get; } = Serilog.Log.ForContext<Migrator>();
@@ -120,15 +116,9 @@ public class Migrator
/*
determine which migrations need to be applied
- first, take the set difference (Except()) of the list of registered migrations and the history file. this gives
- us a list of t he migrations that are not in the history file.
-
- next, check each of the migrations not in history to see if they need to be applied. if they _don't_, then
- add them directly to the history dictionary. if they do, add them to the list of migrations to apply.
-
- the result is:
- - an updated history dictionary, containing the dict loaded from disk plus any new migrations that _don't_ need to be applied
- - a list of migrations that need to be applied
+ take the set difference between all registered migrations and the history file, then for each of the migrations
+ in that set, check to see if it needs to be applied. if it doesn't, add it to the history file with the current
+ timestamp. if it does, add it to the list of migrations to apply.
*/
List<string> migrationsToApply = [];
@@ -158,6 +148,8 @@ public class Migrator
if (migrationsToApply.Count == 0)
{
+ // write the history file to disk; if there are new migrations that didn't need to be applied, or the user
+ // used the 'force' flag, the history file on disk and in memory will have diverged.
UpdateHistoryFile(history);
Log.Information("Databases are up to date!");