aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Data/Migrations
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-05-10 16:55:31 -0500
committerJP Dillingham <jp@dillingham.me>2025-05-10 16:55:31 -0500
commit646446c556524674b2c7b87dfd545cb92447e060 (patch)
tree8178442bbb837fa8fa54b166a7e2d7a22d5004a3 /src/slskd/Core/Data/Migrations
parent41725681ffe4164d4acfcfb259eab976541dc00f (diff)
downloadslskd-646446c556524674b2c7b87dfd545cb92447e060.tar.gz
migrator wip
Diffstat (limited to 'src/slskd/Core/Data/Migrations')
-rw-r--r--src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs b/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs
index 7df435b6..f18aba55 100644
--- a/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs
+++ b/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs
@@ -1,4 +1,4 @@
-// <copyright file="z04012025_TransferStateMigration.cs" company="slskd Team">
+// <copyright file="Z04012025_TransferStateMigration.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -29,10 +29,10 @@ using Soulseek;
/// <summary>
/// Updates the Transfers table to:
///
-/// * Add a new StatusDescription (TEXT) column
-/// * Copy the current (string) contents of the Status column to StatusDescription
-/// * Change the type of the Status column to INTEGER
-/// * Set the contents of the Status column to the numeric representation of the existing Status
+/// * Add a new StateDescription (TEXT) column
+/// * Copy the current (string) contents of the State column to StateDescription
+/// * Change the type of the State column to INTEGER
+/// * Set the contents of the State column to the numeric representation of the existing State
///
/// This is necessary because Entity Framework doesn't work with [Flags] enums that are stored
/// as strings; it tries to use bitwise operators to apply HasFlags(), and these obviously don't
@@ -44,16 +44,21 @@ public class Z04012025_TransferStateMigration : IMigration
private string DatabaseName { get; } = "transfers";
private string ConnectionString => $"Data Source={Path.Combine(Program.DataDirectory, $"{DatabaseName}.db")}";
- public void Apply()
+ public bool NeedsToBeApplied()
{
- // first, check the existing database to see if the StatusDescription column exists
- // if it does, the migration has already been applied
+ // first, check the existing database to see if the StateDescription column exists
+ // if it does, the migration has already been applied, or the database has been recreated
var schema = SchemaInspector.GetDatabaseSchema(ConnectionString);
var txfers = schema["Transfers"];
- if (txfers.Any(c => c.Name == "StatusDescription"))
+ return !txfers.Any(c => c.Name == "StateDescription");
+ }
+
+ public void Apply()
+ {
+ if (!NeedsToBeApplied())
{
- Log.Information("Migration {Name} has already been applied", nameof(Z04012025_TransferStateMigration));
+ Log.Information("Migration {Name} is not necessary or has already been applied", nameof(Z04012025_TransferStateMigration));
return;
}