aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-05-03 18:01:19 -0500
committerJP Dillingham <jp@dillingham.me>2025-05-03 18:01:19 -0500
commit3c70698c39ec1fbe4d522f5c0cdde978d84c1cc0 (patch)
treed053037e51408b4df2a59d5bfbc928d66f448ab1
parent207a645006f75a0fb96f2a1b6a72017f94d42c80 (diff)
downloadslskd-3c70698c39ec1fbe4d522f5c0cdde978d84c1cc0.tar.gz
docs, rename migration
-rw-r--r--src/slskd/Core/Data/Migrations/README.md14
-rw-r--r--src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs (renamed from src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs)9
-rw-r--r--src/slskd/Core/Data/Migrator.cs2
3 files changed, 15 insertions, 10 deletions
diff --git a/src/slskd/Core/Data/Migrations/README.md b/src/slskd/Core/Data/Migrations/README.md
index 1f603b42..0cafbe6a 100644
--- a/src/slskd/Core/Data/Migrations/README.md
+++ b/src/slskd/Core/Data/Migrations/README.md
@@ -1,6 +1,6 @@
# Database Migrations
-In the hopefully unlikely event that a migration is necessary, a migration must be written.
+In the hopefully unlikely event that a non-backwards-compatible schema change to a database migration is necessary, a migration must be written.
Migrations are applied by the `Migrator` at startup.
@@ -10,17 +10,21 @@ The `Migrator` creates a backup of each database prior to running any migrations
## Creating a Migration
-Each migration must be created as a class that implements the `IMigration` interface.
+Each migration must be created as a class that implements the `IMigration` interface. The naming convention for migration classes is:
+
+```
+z<MMDDYYYY>_<ShortDescription>Migration
+```
Migrations MUST:
* Figure out where on disk the associated database(s) are located. This is accomplished by combining the static `Program.DataDirectory` variable
and the name(s) of the table(s) that need to be migrated.
-* Log progress, so users can see that the application is performing work while records are updated.
-* Use transactions when performing database operations and using/try catch where appropriate to avoid partially applied migrations.
* Inspect the target database(s) schema to determine whether the migration needs to be applied (if possible)
+* Use transactions when performing database operations and using/try catch where appropriate to avoid partially applied migrations.
+* Log progress, so users can see that the application is performing work while records are updated.
-When the migration is complete, edit the `Migrations` property in the `Migrator` to add the migration to the list in the proper order.
+The new `IMigration` implementation must be added to the dictionary in the `Migrations` property of the `Migrator` in the desired order so that it can be run.
### Above all else, each and every migration **MUST** be idempotent.
diff --git a/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs b/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs
index 1ea3ca87..2210ba13 100644
--- a/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs
+++ b/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs
@@ -1,4 +1,4 @@
-// <copyright file="TransferStateMigration_04012025.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
@@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see https://www.gnu.org/licenses/.
+
// </copyright>
namespace slskd.Migrations;
@@ -38,9 +39,9 @@ using Soulseek;
/// as strings; it tries to use bitwise operators to apply HasFlags(), and these obviously don't
/// work against strings. Not sure why EF didn't complain about this, but here we are.
/// </summary>
-public class TransferStateMigration_04012025 : IMigration
+public class z04012025_TransferStateMigration : IMigration
{
- private ILogger Log { get; } = Serilog.Log.ForContext<TransferStateMigration_04012025>();
+ private ILogger Log { get; } = Serilog.Log.ForContext<z04012025_TransferStateMigration>();
private string DatabaseName { get; } = "transfers";
private string ConnectionString => $"Data Source={Path.Combine(Program.DataDirectory, $"{DatabaseName}.db")}";
@@ -53,7 +54,7 @@ public class TransferStateMigration_04012025 : IMigration
if (txfers.Any(c => c.Name == "StatusDescription"))
{
- Log.Information("Migration {Name} has already been applied", nameof(TransferStateMigration_04012025));
+ Log.Information("Migration {Name} has already been applied", nameof(z04012025_TransferStateMigration));
return;
}
diff --git a/src/slskd/Core/Data/Migrator.cs b/src/slskd/Core/Data/Migrator.cs
index ffaae586..14c97272 100644
--- a/src/slskd/Core/Data/Migrator.cs
+++ b/src/slskd/Core/Data/Migrator.cs
@@ -53,7 +53,7 @@ public class Migrator
/// </summary>
private Dictionary<string, IMigration> Migrations { get; } = new()
{
- { nameof(TransferStateMigration_04012025), new TransferStateMigration_04012025() },
+ { nameof(z04012025_TransferStateMigration), new z04012025_TransferStateMigration() },
};
/// <summary>