From e08b71168e64928f0664eab2b7c070b9d20b6783 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 1 Apr 2025 19:14:06 -0500 Subject: wip --- src/slskd/Program.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index b7fa47d2..50ae7a07 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -596,6 +596,10 @@ namespace slskd services.AddDbContext(DiskConnectionString("transfers")); services.AddDbContext(DiskConnectionString("messaging")); services.AddDbContext(DiskConnectionString("events")); + + // 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()); } services.AddSingleton(); -- cgit v1.2.3 From 47ea1847f89df9ca2ab2e7a51e29bab27f60f89b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 2 Apr 2025 20:42:35 -0500 Subject: migrate if migrator exists --- src/slskd/Core/Migrator.cs | 8 ++++++++ src/slskd/Program.cs | 7 +++++++ 2 files changed, 15 insertions(+) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Core/Migrator.cs b/src/slskd/Core/Migrator.cs index a83f4764..23580336 100644 --- a/src/slskd/Core/Migrator.cs +++ b/src/slskd/Core/Migrator.cs @@ -20,6 +20,7 @@ namespace slskd; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Serilog; using slskd.Migrations; @@ -60,6 +61,13 @@ public class Migrator } } + var migrationsNotYetApplied = Migrations.Keys.Except(history.Keys); + + if (!migrationsNotYetApplied.Any()) + { + Log.Debug("No migrations need to be applied"); + } + foreach (var migration in Migrations) { if (history.TryGetValue(migration.Key, out var timestamp)) diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 50ae7a07..8fbc0522 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -494,6 +494,13 @@ namespace slskd var app = builder.Build(); + var migrator = app.Services.GetService(); + + if (migrator is not null) + { + migrator.Migrate(); + } + // hack: services that exist only to subscribe to the event bus are not referenced by anything else // and are thus never instantiated. force a reference here so they are created. _ = app.Services.GetService(); -- cgit v1.2.3 From 3004a4297466d97b258033c874580a10536716be Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 2 Apr 2025 21:44:24 -0500 Subject: add option to force --- config/slskd.example.yml | 1 + src/slskd/Core/Migrator.cs | 2 +- src/slskd/Core/Options.cs | 8 ++++++++ src/slskd/Program.cs | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 9cd9584f..621b5564 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -10,6 +10,7 @@ # no_connect: false # no_share_scan: false # force_share_scan: false +# force_migrations: false # no_version_check: false # log_sql: false # experimental: false diff --git a/src/slskd/Core/Migrator.cs b/src/slskd/Core/Migrator.cs index 23580336..b9e98f4c 100644 --- a/src/slskd/Core/Migrator.cs +++ b/src/slskd/Core/Migrator.cs @@ -39,7 +39,7 @@ public class Migrator { nameof(TransferStateMigration_04012025), new TransferStateMigration_04012025() }, }; - public void Migrate() + public void Migrate(bool force = false) { Dictionary history = new(); diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 266d04aa..870a1e83 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -391,6 +391,14 @@ namespace slskd [RequiresRestart] public bool ForceShareScan { get; init; } = false; + /// + /// Gets a value indicating whether to force database migrations to be applied on startup. + /// + [Argument(default, "force-migrations")] + [EnvironmentVariable("FORCE_MIGRATIONS")] + [Description("force database migrations to be applied on startup")] + public bool ForceMigrations { get; init; } = false; + /// /// Gets a value indicating whether the application should check for a newer version on startup. /// diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 8fbc0522..068e62ae 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -498,7 +498,7 @@ namespace slskd if (migrator is not null) { - migrator.Migrate(); + migrator.Migrate(force: OptionsAtStartup.Flags.ForceMigrations); } // hack: services that exist only to subscribe to the event bus are not referenced by anything else -- cgit v1.2.3 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/slskd/Program.cs') 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 From 534d8824c4a3f1aae0448a17f734b57ea395c59f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 4 Apr 2025 19:01:17 -0500 Subject: wip --- src/slskd/Common/Waiter.cs | 2 +- src/slskd/Core/Data/Migrations/Migration.cs | 82 ++++++++ .../Migrations/TransferStateMigration_04012025.cs | 155 ++++++++++++++ src/slskd/Core/Data/Migrator.cs | 204 +++++++++++++++++++ .../Migrations/TransferStateMigration_04012025.cs | 151 -------------- src/slskd/Core/Migrator.cs | 222 --------------------- src/slskd/Program.cs | 2 + 7 files changed, 444 insertions(+), 374 deletions(-) create mode 100644 src/slskd/Core/Data/Migrations/Migration.cs create mode 100644 src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs create mode 100644 src/slskd/Core/Data/Migrator.cs delete mode 100644 src/slskd/Core/Migrations/TransferStateMigration_04012025.cs delete mode 100644 src/slskd/Core/Migrator.cs (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Common/Waiter.cs b/src/slskd/Common/Waiter.cs index f8b3d305..d32f23b4 100644 --- a/src/slskd/Common/Waiter.cs +++ b/src/slskd/Common/Waiter.cs @@ -450,7 +450,7 @@ namespace slskd if (disposing) { CancellationTokenRegistration.Dispose(); - TimeoutTokenSource.Dispose(); + TimeoutTokenSource?.Dispose(); TimeoutTokenRegistration.Dispose(); } diff --git a/src/slskd/Core/Data/Migrations/Migration.cs b/src/slskd/Core/Data/Migrations/Migration.cs new file mode 100644 index 00000000..02f87a9c --- /dev/null +++ b/src/slskd/Core/Data/Migrations/Migration.cs @@ -0,0 +1,82 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// 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/. +// + +namespace slskd.Migrations; + +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.Data.Sqlite; + +public record ColumnInfo(long Cid, string Name, string Type, bool NotNull, object DefaultValue, bool PrimaryKey); + +public abstract class Migration +{ + public Migration(string databaseName) + { + DatabaseName = databaseName; + } + + public string DatabaseName { get; } + public string DatabaseFileName => Path.Combine(Program.DataDirectory, DatabaseName); + public string ConnectionString => $"Data Source={DatabaseFileName}.db"; + + public abstract void Apply(); + + protected Dictionary> GetDatabaseSchema() + { + try + { + using var connection = new SqliteConnection(ConnectionString); + connection.Open(); + + var dict = new Dictionary>(); + + using var tableCommand = new SqliteCommand("SELECT name FROM sqlite_master WHERE type='table';", connection); + using var tableReader = tableCommand.ExecuteReader(); + + while (tableReader.Read()) + { + var table = tableReader.GetString(0); + + var columns = new List(); + + using var columnCommand = new SqliteCommand($"PRAGMA table_info({table});", connection); + using var cr = columnCommand.ExecuteReader(); + + while (cr.Read()) + { + columns.Add(new ColumnInfo( + Cid: cr.GetInt64(cr.GetOrdinal("cid")), + Name: cr.GetString(cr.GetOrdinal("name")), + Type: cr.GetString(cr.GetOrdinal("type")), + NotNull: cr.GetInt64(cr.GetOrdinal("notnull")) > 0, + DefaultValue: cr["dflt_value"], + PrimaryKey: cr.GetInt64(cr.GetOrdinal("pk")) > 0)); + } + + dict[table] = columns; + } + + return dict; + } + catch (Exception ex) + { + throw new SlskdException($"Failed to retrieve schema information for database '{DatabaseName}'. The database might be corrupt or in use by another application; if the problem persists the file ({DatabaseFileName}) may need to be deleted", ex); + } + } +} \ No newline at end of file diff --git a/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs b/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs new file mode 100644 index 00000000..37171a77 --- /dev/null +++ b/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs @@ -0,0 +1,155 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// 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/. +// + +namespace slskd.Migrations; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.Json; +using Microsoft.Data.Sqlite; +using Serilog; + +/// +/// 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 +/// +/// 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 +/// work against strings. Not sure why EF didn't complain about this, but here we are. +/// +public class TransferStateMigration_04012025 : Migration +{ + public TransferStateMigration_04012025(string databasName) + : base(databasName) + { + } + + private string DbName => "transfers"; + private ILogger Log { get; } = Serilog.Log.ForContext(); + + public override void Apply() + { + // first, check the existing database to see if the StatusDescription column exists + // if it does, the migration has already been applied + var schema = GetDatabaseSchema(); + var txfers = schema["Transfers"]; + + if (txfers.Any(c => c.Name == "StatusDescription")) + { + Log.Information("Migration {Name} has already been applied", nameof(TransferStateMigration_04012025)); + return; + } + + AddStateDescriptionColumn(Path.Combine(Program.DataDirectory, "transfers.db")); + } + + static void AddStateDescriptionColumn(string dbPath) + { + if (!File.Exists(dbPath)) + { + Console.WriteLine("Database file not found."); + return; + } + + string connectionString = $"Data Source={dbPath};"; + + using (var connection = new SqliteConnection(connectionString)) + { + connection.Open(); + + using (var transaction = connection.BeginTransaction()) + { + try + { + // Rename old table + using (var renameCommand = new SqliteCommand("ALTER TABLE Transfers RENAME TO Transfers_old;", connection)) + { + renameCommand.ExecuteNonQuery(); + } + + // Create new table with StateDescription after State + string createNewTableSQL = @" + CREATE TABLE Transfers ( + Id TEXT NOT NULL, + Username TEXT, + Direction TEXT NOT NULL, + Filename TEXT, + Size INTEGER NOT NULL, + StartOffset INTEGER NOT NULL, + State INTEGER NOT NULL, + StateDescription TEXT, -- New column + RequestedAt TEXT NOT NULL, + EnqueuedAt TEXT, + StartedAt TEXT, + EndedAt TEXT, + BytesTransferred INTEGER NOT NULL, + AverageSpeed REAL NOT NULL, + PlaceInQueue INTEGER, + Exception TEXT, + Removed INTEGER NOT NULL, + CONSTRAINT PK_Transfers PRIMARY KEY(Id) + );"; + + using (var createCommand = new SqliteCommand(createNewTableSQL, connection)) + { + createCommand.ExecuteNonQuery(); + } + + // Copy data into the new table + string copyDataSQL = @" + INSERT INTO Transfers ( + Id, Username, Direction, Filename, Size, StartOffset, State, + RequestedAt, EnqueuedAt, StartedAt, EndedAt, BytesTransferred, + AverageSpeed, PlaceInQueue, Exception, Removed + ) + SELECT + Id, Username, Direction, Filename, Size, StartOffset, State, + RequestedAt, EnqueuedAt, StartedAt, EndedAt, BytesTransferred, + AverageSpeed, PlaceInQueue, Exception, Removed + FROM Transfers_old;"; + + using (var copyCommand = new SqliteCommand(copyDataSQL, connection)) + { + copyCommand.ExecuteNonQuery(); + } + + // Drop the old table + using (var dropCommand = new SqliteCommand("DROP TABLE Transfers_old;", connection)) + { + dropCommand.ExecuteNonQuery(); + } + + transaction.Commit(); + Console.WriteLine("Column 'StateDescription' added successfully."); + } + catch (Exception ex) + { + transaction.Rollback(); + Console.WriteLine($"Error: {ex.Message}"); + } + } + + connection.Close(); + } + } +} diff --git a/src/slskd/Core/Data/Migrator.cs b/src/slskd/Core/Data/Migrator.cs new file mode 100644 index 00000000..f3543ca9 --- /dev/null +++ b/src/slskd/Core/Data/Migrator.cs @@ -0,0 +1,204 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// 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/. +// + +namespace slskd; + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using Serilog; +using slskd.Migrations; + +/// +/// Applies database migrations. +/// +public class Migrator +{ + /// + /// Initializes a new instance of the class. + /// + /// A list of known databases. + public Migrator(params string[] databases) + { + Databases = databases; + } + + private string HistoryFileName { get; } = Path.Combine(Program.DataDirectory, "migration.history"); + private IEnumerable Databases { get; } + private ILogger Log { get; } = Serilog.Log.ForContext(); + + /// + /// A map of all migrations, to be applied in the order they are specified (descending). + /// + private Dictionary Migrations { get; } = new() + { + { nameof(TransferStateMigration_04012025), new TransferStateMigration_04012025("transfers") }, + }; + + /// + /// Applies database migrations. + /// + /// Apply all migrations, regardless of whether there's evidence they have been applied already. + public void Migrate(bool force = false) + { + Dictionary history = []; + + Log.Information("Checking for outstanding database migrations..."); + + // load migration history from the history file in the root of the data directory. this file contains a key/value + // pair for each migration that's been applied, along with the migration date. + // if force=true, we don't care about the history and there's no reason to look at it. + if (!force) + { + try + { + if (File.Exists(HistoryFileName)) + { + var txt = File.ReadAllText(HistoryFileName); + history = txt.FromJson>(); + + Log.Debug("Loaded migration history from {HistoryFile}: {History}", HistoryFileName, history); + } + else + { + Log.Debug("Migration history file {HistoryFile} was not found", HistoryFileName); + } + } + catch (Exception ex) + { + // log a message but don't throw; migrations are (should be!) idempotent, so there's no harm in running them, + // it just takes unnecessary time. + Log.Warning("Failed to load migration history from {HistoryFile}: {Message}", HistoryFileName, ex.Message); + Log.Warning("Migration history will be overwritten and all migrations will be applied"); + } + } + + // figure out which migrations need to be applied by taking the set difference of the migration list and the history contents + var migrationsNotYetApplied = Migrations.Keys.Except(history.Keys); + + if (!migrationsNotYetApplied.Any()) + { + Log.Information("Databases are up to date"); + return; + } + + Log.Warning("{Count} outstanding database migration(s) to apply. This operation must be completed before the application can start.", migrationsNotYetApplied.Count()); + + // take some simple backups before we do anything. this gives users a way to get back to a working configuration + // if the migration is interrupted, fails, or if the user wants to revert to the previous version. these files + // must be left in place after the migration completes, and they'll be overwritten the next time a migration is applied + try + { + Log.Information("Backing up existing databases..."); + + foreach (var database in Databases) + { + var name = Path.Combine(Program.DataDirectory, database); + var src = $"{name}.db"; + var dest = $"{name}.db.pre-migration"; + + File.Copy(src, dest, overwrite: true); + + Log.Information("Backed database {Original} up to {Backup}", src, dest); + } + + Log.Information("Databases backed up successfully"); + } + catch (Exception ex) + { + Log.Fatal(ex, "Failed to back up one or more database(s) prior to migration, operation cannot continue: {Message}", ex.Message); + Log.Fatal("Try again, revert the application to the previous version, or delete existing databases (warning: history will be lost!) to continue"); + throw; + } + + // we know which migrations to apply, and we've backed all of the databases up. let's go! + try + { + Log.Warning("Beginning migration(s)"); + Log.Warning("This may take some time. Avoid stopping the application before the process is complete. If the process is interrupted it may be necessary to manually revert to backups."); + + var overallSw = new Stopwatch(); + overallSw.Start(); + + var current = 0; + var total = migrationsNotYetApplied.Count(); + + var currentSw = new Stopwatch(); + + foreach (var migration in migrationsNotYetApplied) + { + current++; + currentSw.Restart(); + + Log.Warning("Applying migration {Name} ({Current} of {Total})", migration, current, total); + + try + { + Migrations[migration].Apply(); + history[migration] = DateTime.UtcNow; + + Log.Information("Migration {Name} was applied successfully (elapsed: {Duration}ms)", migration, currentSw.ElapsedMilliseconds); + } + catch (Exception ex) + { + Log.Fatal(ex, "Failed to apply migration {Name}: {Message}", migration, ex.Message); + throw; + } + } + + Log.Information("{Count} migration(s) applied successfully (elapsed: {Duration}ms elapsed)", total, overallSw.ElapsedMilliseconds); + } + catch (Exception ex) + { + Log.Fatal(ex, "Failed to apply one or more migration(s): {Message}", ex.Message); + + try + { + Log.Information("Attempting to restore databases from backups..."); + + foreach (var database in Databases) + { + var name = Path.Combine(Program.DataDirectory, database); + var src = $"{name}.db.pre-migration"; + var dest = $"{name}.db"; + + // note: leave the backup in place to give users peace of mind + File.Copy(src, dest, overwrite: true); + + Log.Information("Restored {Original} from {Backup}", dest, src); + } + + Log.Information("Databases restored successfully"); + } + catch (Exception restoreEx) + { + Log.Fatal(restoreEx, "Failed to restore one or more databases from backup: {Message}", restoreEx.Message); + Log.Fatal("Restore manually by renaming '.db.pre-migration' to '.db' prior to starting the application again."); + } + + throw new SlskdException("Failed to apply one or more database migrations. See inner Exception for details.", ex); + } + + var newHistory = history.ToJson(); + File.WriteAllText(HistoryFileName, newHistory); // overwrites existing, if present + Log.Debug("Saved history to {Location}: {History}", HistoryFileName, newHistory); + + Log.Information("Migration(s) complete"); + } +} \ No newline at end of file diff --git a/src/slskd/Core/Migrations/TransferStateMigration_04012025.cs b/src/slskd/Core/Migrations/TransferStateMigration_04012025.cs deleted file mode 100644 index ea295851..00000000 --- a/src/slskd/Core/Migrations/TransferStateMigration_04012025.cs +++ /dev/null @@ -1,151 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// 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/. -// - -namespace slskd.Migrations; - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Microsoft.Data.Sqlite; - -public class TransferStateMigration_04012025 : IMigration -{ - private string DbName => "transfers"; - - public void Apply(IEnumerable databases) - { - if (!databases.Contains(DbName)) - { - throw new SlskdException($"Attempting to migrate database {DbName} but {DbName} is not in the list of known databases ({string.Join(",", databases)}). This is a precautionary check to ensure databases are properly backed up prior to migration, and the check has failed. Only an application update can fix this; please create an urgent issue: {Program.IssuesUrl}"); - } - } - - static void AddStateDescriptionColumn(string dbPath) - { - if (!File.Exists(dbPath)) - { - Console.WriteLine("Database file not found."); - return; - } - - string connectionString = $"Data Source={dbPath};Version=3;"; - - using (var connection = new SqliteConnection(connectionString)) - { - connection.Open(); - - // Check if the column exists - bool columnExists = false; - using (var command = new SqliteCommand("PRAGMA table_info(Transfers);", connection)) - using (var reader = command.ExecuteReader()) - { - while (reader.Read()) - { - string columnName = reader["name"].ToString(); - if (columnName.Equals("StateDescription", StringComparison.OrdinalIgnoreCase)) - { - columnExists = true; - break; - } - } - } - - if (columnExists) - { - Console.WriteLine("Column 'StateDescription' already exists."); - return; - } - - Console.WriteLine("Adding 'StateDescription' column..."); - - using (var transaction = connection.BeginTransaction()) - { - try - { - // Rename old table - using (var renameCommand = new SqliteCommand("ALTER TABLE Transfers RENAME TO Transfers_old;", connection)) - { - renameCommand.ExecuteNonQuery(); - } - - // Create new table with StateDescription after State - string createNewTableSQL = @" - CREATE TABLE Transfers ( - Id TEXT NOT NULL, - Username TEXT, - Direction TEXT NOT NULL, - Filename TEXT, - Size INTEGER NOT NULL, - StartOffset INTEGER NOT NULL, - State TEXT NOT NULL, - StateDescription TEXT, -- New column - RequestedAt TEXT NOT NULL, - EnqueuedAt TEXT, - StartedAt TEXT, - EndedAt TEXT, - BytesTransferred INTEGER NOT NULL, - AverageSpeed REAL NOT NULL, - PlaceInQueue INTEGER, - Exception TEXT, - Removed INTEGER NOT NULL, - CONSTRAINT PK_Transfers PRIMARY KEY(Id) - );"; - - using (var createCommand = new SqliteCommand(createNewTableSQL, connection)) - { - createCommand.ExecuteNonQuery(); - } - - // Copy data into the new table - string copyDataSQL = @" - INSERT INTO Transfers ( - Id, Username, Direction, Filename, Size, StartOffset, State, - RequestedAt, EnqueuedAt, StartedAt, EndedAt, BytesTransferred, - AverageSpeed, PlaceInQueue, Exception, Removed - ) - SELECT - Id, Username, Direction, Filename, Size, StartOffset, State, - RequestedAt, EnqueuedAt, StartedAt, EndedAt, BytesTransferred, - AverageSpeed, PlaceInQueue, Exception, Removed - FROM Transfers_old;"; - - using (var copyCommand = new SqliteCommand(copyDataSQL, connection)) - { - copyCommand.ExecuteNonQuery(); - } - - // Drop the old table - using (var dropCommand = new SqliteCommand("DROP TABLE Transfers_old;", connection)) - { - dropCommand.ExecuteNonQuery(); - } - - transaction.Commit(); - Console.WriteLine("Column 'StateDescription' added successfully."); - } - catch (Exception ex) - { - transaction.Rollback(); - Console.WriteLine($"Error: {ex.Message}"); - } - } - - connection.Close(); - } - } -} diff --git a/src/slskd/Core/Migrator.cs b/src/slskd/Core/Migrator.cs deleted file mode 100644 index 86056751..00000000 --- a/src/slskd/Core/Migrator.cs +++ /dev/null @@ -1,222 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// 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/. -// - -namespace slskd; - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Serilog; -using slskd.Migrations; - -/// -/// A database migration. -/// -public interface IMigration -{ - /// - /// Apply the database migration. - /// - /// - /// The database list is included to help ensure that we're backing up databases before we start. Migrations - /// must check the supplied list to ensure the database(s) they are attempting to migrate are included; if - /// they are missing they haven't been backed up. - /// - /// A list of known databases. - public void Apply(IEnumerable databases); -} - -/// -/// Applies database migrations. -/// -public class Migrator -{ - /// - /// Initializes a new instance of the class. - /// - /// A list of known databases. - public Migrator(params string[] databases) - { - Databases = databases; - } - - private string HistoryFileName { get; } = Path.Combine(Program.DataDirectory, "migration.history"); - private IEnumerable Databases { get; } - private ILogger Log { get; } = Serilog.Log.ForContext(); - - /// - /// A map of all migrations, to be applied in the order they are specified (descending). - /// - private Dictionary Migrations { get; } = new() - { - { nameof(TransferStateMigration_04012025), new TransferStateMigration_04012025() }, - }; - - /// - /// Applies database migrations. - /// - /// Apply all migrations, regardless of whether there's evidence they have been applied already. - public void Migrate(bool force = false) - { - Dictionary history = []; - - Log.Information("Checking for outstanding database migrations..."); - - // load migration history from the history file in the root of the data directory. this file contains a key/value - // pair for each migration that's been applied, along with the migration date. - // if force=true, we don't care about the history and there's no reason to look at it. - if (!force) - { - try - { - if (File.Exists(HistoryFileName)) - { - var txt = File.ReadAllText(HistoryFileName); - history = txt.FromJson>(); - - Log.Debug("Loaded migration history from {HistoryFile}: {History}", HistoryFileName, history); - } - else - { - Log.Debug("Migration history file {HistoryFile} was not found", HistoryFileName); - } - } - catch (Exception ex) - { - // log a message but don't throw; migrations are (should be!) idempotent, so there's no harm in running them, - // it just takes unnecessary time. - Log.Warning("Failed to load migration history from {HistoryFile}: {Message}", HistoryFileName, ex.Message); - Log.Warning("Migration history will be overwritten and all migrations will be applied"); - } - } - - // figure out which migrations need to be applied by taking the set difference of the migration list and the history contents - var migrationsNotYetApplied = Migrations.Keys.Except(history.Keys); - - if (!migrationsNotYetApplied.Any()) - { - Log.Information("Databases are up to date"); - return; - } - - Log.Warning("{Count} outstanding database migration(s) to apply. This operation must be completed before the application can start.", migrationsNotYetApplied.Count()); - - // take some simple backups before we do anything. this gives users a way to get back to a working configuration - // if the migration is interrupted, fails, or if the user wants to revert to the previous version. these files - // must be left in place after the migration completes, and they'll be overwritten the next time a migration is applied - try - { - Log.Information("Backing up existing databases..."); - - foreach (var database in Databases) - { - var name = Path.Combine(Program.DataDirectory, database); - var src = $"{name}.db"; - var dest = $"{name}.db.pre-migration"; - - File.Copy(src, dest, overwrite: true); - - Log.Information("Backed database {Original} up to {Backup}", src, dest); - } - - Log.Information("Databases backed up successfully"); - } - catch (Exception ex) - { - Log.Fatal(ex, "Failed to back up one or more database(s) prior to migration, operation cannot continue: {Message}", ex.Message); - Log.Fatal("Try again, revert the application to the previous version, or delete existing databases (warning: history will be lost!) to continue"); - throw; - } - - // we know which migrations to apply, and we've backed all of the databases up. let's go! - try - { - Log.Warning("Beginning migration(s)"); - Log.Warning("This may take some time. Avoid stopping the application before the process is complete. If the process is interrupted it may be necessary to manually revert to backups."); - - var overallSw = new Stopwatch(); - overallSw.Start(); - - var current = 0; - var total = migrationsNotYetApplied.Count(); - - var currentSw = new Stopwatch(); - - foreach (var migration in migrationsNotYetApplied) - { - current++; - currentSw.Restart(); - - Log.Warning("Applying migration {Name} ({Current} of {Total})", migration, current, total); - - try - { - Migrations[migration].Apply(Databases); - history[migration] = DateTime.UtcNow; - - Log.Information("Migration {Name} was applied successfully (elapsed: {Duration}ms)", migration, currentSw.ElapsedMilliseconds); - } - catch (Exception ex) - { - Log.Fatal(ex, "Failed to apply migration {Name}: {Message}", migration, ex.Message); - throw; - } - } - - Log.Information("{Count} migration(s) applied successfully (elapsed: {Duration}ms elapsed)", total, overallSw.ElapsedMilliseconds); - } - catch (Exception ex) - { - Log.Fatal(ex, "Failed to apply one or more migration(s): {Message}", ex.Message); - - try - { - Log.Information("Attempting to restore databases from backups..."); - - foreach (var database in Databases) - { - var name = Path.Combine(Program.DataDirectory, database); - var src = $"{name}.db.pre-migration"; - var dest = $"{name}.db"; - - // note: leave the backup in place to give users peace of mind - File.Copy(src, dest, overwrite: true); - - Log.Information("Restored {Original} from {Backup}", dest, src); - } - - Log.Information("Databases restored successfully"); - } - catch (Exception restoreEx) - { - Log.Fatal(restoreEx, "Failed to restore one or more databases from backup: {Message}", restoreEx.Message); - Log.Fatal("Restore manually by renaming '.db.pre-migration' to '.db' prior to starting the application again."); - throw; - } - - throw; - } - - var newHistory = history.ToJson(); - File.WriteAllText(HistoryFileName, newHistory); // overwrites existing, if present - Log.Debug("Saved history to {Location}: {History}", HistoryFileName, newHistory); - - Log.Information("Migration(s) complete"); - } -} \ No newline at end of file diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 690960a7..763b345a 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -500,6 +500,8 @@ namespace slskd app.Services.GetService().Migrate(force: OptionsAtStartup.Flags.ForceMigrations); } + Environment.Exit(1); + // hack: services that exist only to subscribe to the event bus are not referenced by anything else // and are thus never instantiated. force a reference here so they are created. _ = app.Services.GetService(); -- cgit v1.2.3 From e4d5e2cce9f4400c901284da5d5c4f7be548bd88 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 3 May 2025 17:19:44 -0500 Subject: make a dedicated backup directory --- src/slskd/Program.cs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 763b345a..f1cb441f 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -187,6 +187,11 @@ namespace slskd /// public static string DataDirectory { get; private set; } = null; + /// + /// Gets the path where database migration information is saved. + /// + public static string DataMigrationsDirectory { get; private set; } = null; + /// /// Gets the default fully qualified path to the configuration file. /// @@ -353,6 +358,7 @@ namespace slskd { VerifyDirectory(AppDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(DataDirectory, createIfMissing: true, verifyWriteable: true); + VerifyDirectory(DataMigrationsDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(ScriptDirectory, createIfMissing: true, verifyWriteable: false); VerifyDirectory(DefaultDownloadsDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(DefaultIncompleteDirectory, createIfMissing: true, verifyWriteable: true); @@ -496,10 +502,13 @@ namespace slskd if (!OptionsAtStartup.Flags.Volatile) { + Log.Debug($"Running migrations..."); + // note: if this ever throws, we've forgotten to register a Migrator following database DI config app.Services.GetService().Migrate(force: OptionsAtStartup.Flags.ForceMigrations); } + // todo: don't forget to take this out Environment.Exit(1); // hack: services that exist only to subscribe to the event bus are not referenced by anything else -- cgit v1.2.3 From 207a645006f75a0fb96f2a1b6a72017f94d42c80 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 3 May 2025 17:53:05 -0500 Subject: adjust logs --- src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs | 8 ++++++++ src/slskd/Core/Data/Migrator.cs | 8 ++++---- src/slskd/Program.cs | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs b/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs index 7229eee4..1ea3ca87 100644 --- a/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs +++ b/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs @@ -131,6 +131,8 @@ public class TransferStateMigration_04012025 : IMigration using var createCommand = new SqliteCommand(create, connection, transaction); createCommand.ExecuteNonQuery(); + Log.Information("Schema changes applied, copying data..."); + /* copy the existing data into the new table */ @@ -149,6 +151,8 @@ public class TransferStateMigration_04012025 : IMigration using var copyCommand = new SqliteCommand(copy, connection, transaction); copyCommand.ExecuteNonQuery(); + Log.Information("Data copied, adjusting columns..."); + /* we no longer need the old table, so drop it */ @@ -170,10 +174,13 @@ public class TransferStateMigration_04012025 : IMigration sprinkled in. this should run in reasonable time for large collections */ var sw = new Stopwatch(); + var step = 1; foreach (var state in stateMapping) { sw.Reset(); + Log.Information("> Updating column {Step} of {Total}. This may take some time...", step++, stateMapping.Count); + Log.Debug("Setting {String} to {Int}", state.Key, state.Value); var mapCommand = new SqliteCommand($"UPDATE Transfers SET State = {state.Value} WHERE State = '{state.Key}';", connection, transaction); @@ -185,6 +192,7 @@ public class TransferStateMigration_04012025 : IMigration Log.Debug("Committing transation..."); transaction.Commit(); Log.Debug("Transaction committed!"); + Log.Information("Done!"); } catch (Exception) { diff --git a/src/slskd/Core/Data/Migrator.cs b/src/slskd/Core/Data/Migrator.cs index 69294cf5..ffaae586 100644 --- a/src/slskd/Core/Data/Migrator.cs +++ b/src/slskd/Core/Data/Migrator.cs @@ -99,7 +99,7 @@ public class Migrator if (!migrationsNotYetApplied.Any()) { - Log.Information("Databases are up to date"); + Log.Information("Databases are up to date!"); return; } @@ -107,7 +107,7 @@ public class Migrator var migrationId = DateTime.UtcNow.ToString("MMddyy_hhmmss"); - Log.Warning("-----> The ID for this migration is {MigrationId}. Use it to locate pre-migration database backups, should manual cleanup be needed. <-----", migrationId); + Log.Warning("--> The ID for this migration is {MigrationId}. Use it to locate pre-migration database backups, should manual cleanup be needed. <--", migrationId); // take some simple backups before we do anything. this gives users a way to get back to a working configuration // if the migration is interrupted, fails, or if the user wants to revert to the previous version. these files @@ -170,7 +170,7 @@ public class Migrator } } - Log.Information("{Count} migration(s) applied successfully (elapsed: {Duration}ms elapsed)", total, overallSw.ElapsedMilliseconds); + Log.Information("{Count} migration(s) applied successfully (elapsed: {Duration}ms)", total, overallSw.ElapsedMilliseconds); } catch (Exception ex) { @@ -207,7 +207,7 @@ public class Migrator File.WriteAllText(HistoryFileName, newHistory); // overwrites existing, if present Log.Debug("Saved history to {Location}: {History}", HistoryFileName, newHistory); - Log.Information("Migration(s) complete"); + Log.Information("Migration(s) complete!"); } private string MakeSourceDatabasePath(string database) => Path.Combine(Program.DataDirectory, $"{database}.db"); diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index f1cb441f..f1e9e7f5 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -341,6 +341,7 @@ namespace slskd // derive the application directory value and defaults that are dependent upon it AppDirectory ??= DefaultAppDirectory; DataDirectory = Path.Combine(AppDirectory, "data"); + DataMigrationsDirectory = Path.Combine(DataDirectory, "migrations"); LogDirectory = Path.Combine(AppDirectory, "logs"); ScriptDirectory = Path.Combine(AppDirectory, "scripts"); @@ -502,7 +503,7 @@ namespace slskd if (!OptionsAtStartup.Flags.Volatile) { - Log.Debug($"Running migrations..."); + Log.Information($"Running migrations..."); // note: if this ever throws, we've forgotten to register a Migrator following database DI config app.Services.GetService().Migrate(force: OptionsAtStartup.Flags.ForceMigrations); -- cgit v1.2.3 From 7477d42487237d231fa8f9203ddbe567e03bf616 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 10 May 2025 14:48:31 -0500 Subject: remove early exit --- src/slskd/Program.cs | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index f1e9e7f5..49c46902 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -509,9 +509,6 @@ namespace slskd app.Services.GetService().Migrate(force: OptionsAtStartup.Flags.ForceMigrations); } - // todo: don't forget to take this out - Environment.Exit(1); - // hack: services that exist only to subscribe to the event bus are not referenced by anything else // and are thus never instantiated. force a reference here so they are created. _ = app.Services.GetService(); -- cgit v1.2.3 From 96e716e9d3d4ac522497d7a231f95e02273261da Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 10 May 2025 14:48:42 -0500 Subject: fix header --- .../Core/Data/Migrations/z04012025_TransferStateMigration.cs | 7 +++---- src/slskd/Core/Data/Migrator.cs | 8 +++++++- src/slskd/Program.cs | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs b/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs index 2210ba13..7df435b6 100644 --- a/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs +++ b/src/slskd/Core/Data/Migrations/z04012025_TransferStateMigration.cs @@ -13,7 +13,6 @@ // // 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/. - // namespace slskd.Migrations; @@ -39,9 +38,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. /// -public class z04012025_TransferStateMigration : IMigration +public class Z04012025_TransferStateMigration : IMigration { - private ILogger Log { get; } = Serilog.Log.ForContext(); + private ILogger Log { get; } = Serilog.Log.ForContext(); private string DatabaseName { get; } = "transfers"; private string ConnectionString => $"Data Source={Path.Combine(Program.DataDirectory, $"{DatabaseName}.db")}"; @@ -54,7 +53,7 @@ public class z04012025_TransferStateMigration : IMigration if (txfers.Any(c => c.Name == "StatusDescription")) { - Log.Information("Migration {Name} has already been applied", nameof(z04012025_TransferStateMigration)); + 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 14c97272..1312681c 100644 --- a/src/slskd/Core/Data/Migrator.cs +++ b/src/slskd/Core/Data/Migrator.cs @@ -25,8 +25,14 @@ using System.Linq; using Serilog; using slskd.Migrations; +/// +/// Applies database migrations. +/// public interface IMigration { + /// + /// Applies the migration. + /// void Apply(); } @@ -53,7 +59,7 @@ public class Migrator /// private Dictionary Migrations { get; } = new() { - { nameof(z04012025_TransferStateMigration), new z04012025_TransferStateMigration() }, + { nameof(Z04012025_TransferStateMigration), new Z04012025_TransferStateMigration() }, }; /// diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 49c46902..844d8a27 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -503,7 +503,7 @@ namespace slskd if (!OptionsAtStartup.Flags.Volatile) { - Log.Information($"Running migrations..."); + Log.Debug($"Running Migrate()..."); // note: if this ever throws, we've forgotten to register a Migrator following database DI config app.Services.GetService().Migrate(force: OptionsAtStartup.Flags.ForceMigrations); -- cgit v1.2.3 From 7a44729293863b494fd929b91f349f47b8603e7c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 May 2025 12:58:05 -0500 Subject: migrations -> backups --- src/slskd/Core/Data/Migrator.cs | 6 +++--- src/slskd/Program.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Core/Data/Migrator.cs b/src/slskd/Core/Data/Migrator.cs index 4adc22fb..4cc56147 100644 --- a/src/slskd/Core/Data/Migrator.cs +++ b/src/slskd/Core/Data/Migrator.cs @@ -59,7 +59,6 @@ public class Migrator Databases = databases; } - private string HistoryFileName { get; } = Path.Combine(Program.DataMigrationsDirectory, "history"); private IEnumerable Databases { get; } private ILogger Log { get; } = Serilog.Log.ForContext(); @@ -94,7 +93,8 @@ public class Migrator { foreach (var migration in Migrations.Keys) { - if (!Migrations[migration].NeedsToBeApplied()) // warning: performs I/O + // warning: performs I/O + if (!Migrations[migration].NeedsToBeApplied()) { Log.Debug("Migration {Name} does not need to be applied", migration); migrationsToSkip.Add(migration); @@ -227,5 +227,5 @@ public class Migrator } private string MakeSourceDatabasePath(string database) => Path.Combine(Program.DataDirectory, $"{database}.db"); - private string MakeBackupDatabasePath(string database, string timestamp) => Path.Combine(Program.DataMigrationsDirectory, $"{database}.pre-migration-backup.{timestamp}.db"); + private string MakeBackupDatabasePath(string database, string timestamp) => Path.Combine(Program.DataBackupDirectory, $"{database}.pre-migration-backup.{timestamp}.db"); } \ No newline at end of file diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 844d8a27..0537824f 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -188,9 +188,9 @@ namespace slskd public static string DataDirectory { get; private set; } = null; /// - /// Gets the path where database migration information is saved. + /// Gets the path where backups of persistent data saved. /// - public static string DataMigrationsDirectory { get; private set; } = null; + public static string DataBackupDirectory { get; private set; } = null; /// /// Gets the default fully qualified path to the configuration file. @@ -341,7 +341,7 @@ namespace slskd // derive the application directory value and defaults that are dependent upon it AppDirectory ??= DefaultAppDirectory; DataDirectory = Path.Combine(AppDirectory, "data"); - DataMigrationsDirectory = Path.Combine(DataDirectory, "migrations"); + DataBackupDirectory = Path.Combine(DataDirectory, "backups"); LogDirectory = Path.Combine(AppDirectory, "logs"); ScriptDirectory = Path.Combine(AppDirectory, "scripts"); @@ -359,7 +359,7 @@ namespace slskd { VerifyDirectory(AppDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(DataDirectory, createIfMissing: true, verifyWriteable: true); - VerifyDirectory(DataMigrationsDirectory, createIfMissing: true, verifyWriteable: true); + VerifyDirectory(DataBackupDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(ScriptDirectory, createIfMissing: true, verifyWriteable: false); VerifyDirectory(DefaultDownloadsDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(DefaultIncompleteDirectory, createIfMissing: true, verifyWriteable: true); -- cgit v1.2.3 From d57d8a065bc384442199a91a7a388dc14b733f9e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 26 May 2025 17:50:08 -0500 Subject: update typo'ed error message --- src/slskd/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 0537824f..dd85bc21 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -674,7 +674,7 @@ namespace slskd if (SQLitePCL.raw.sqlite3_config(SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED) != SQLitePCL.raw.SQLITE_OK) { - throw new InvalidOperationException($"SQLite threading mode could not be set to . Please create a GitHub issue to report this and include details about your environment."); + throw new InvalidOperationException($"SQLite threading mode could not be set to SERIALIZED ({SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED}). Please create a GitHub issue to report this and include details about your environment."); } Log.Debug("SQLite threading mode set to {Mode} ({Number})", "SERIALIZED", SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED); -- cgit v1.2.3