diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-05-03 17:53:05 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-05-03 17:53:05 -0500 |
| commit | 207a645006f75a0fb96f2a1b6a72017f94d42c80 (patch) | |
| tree | 529c7ccc6c34cdbf84bb27de8109428ada7fc9a0 /src | |
| parent | d43c1aba9c07258d9f7f0b9ba59eb6fe33d4bb2c (diff) | |
| download | slskd-207a645006f75a0fb96f2a1b6a72017f94d42c80.tar.gz | |
adjust logs
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs | 8 | ||||
| -rw-r--r-- | src/slskd/Core/Data/Migrator.cs | 8 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 3 |
3 files changed, 14 insertions, 5 deletions
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<Migrator>().Migrate(force: OptionsAtStartup.Flags.ForceMigrations); |
