diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-05-25 17:53:31 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-05-25 17:53:31 -0500 |
| commit | 930df71e94dedd5de5267418c3e7666a86eea416 (patch) | |
| tree | 083ea0dd1f3147c7f8e38a82e2df788562897c97 | |
| parent | 7a44729293863b494fd929b91f349f47b8603e7c (diff) | |
| download | slskd-930df71e94dedd5de5267418c3e7666a86eea416.tar.gz | |
final tweaks
| -rw-r--r-- | docs/migrations.md | 6 | ||||
| -rw-r--r-- | src/slskd/Core/Data/IMigration.cs | 38 | ||||
| -rw-r--r-- | src/slskd/Core/Data/Migrations/README.md | 4 | ||||
| -rw-r--r-- | src/slskd/Core/Data/Migrator.cs | 20 |
4 files changed, 42 insertions, 26 deletions
diff --git a/docs/migrations.md b/docs/migrations.md index 2b6450ca..2fec53bd 100644 --- a/docs/migrations.md +++ b/docs/migrations.md @@ -6,7 +6,7 @@ Database migrations are used to update the structure of the application's databa When the application detects that a migration is required, it performs the following steps: -1. Back up existing databases: Before applying any changes, the application creates a backup of each database. These backups are stored in the `migrations` directory within the application's data directory. The backup files are named using the format `<database>.pre-migration-backup.<migration id>.db`. +1. Back up existing databases: Before applying any changes, the application creates a backup of each database. These backups are stored in the `backups` directory within the application's data directory. The backup files are named using the format `<database>.pre-migration-backup.<migration id>.db`. 2. Apply migrations: The application applies the necessary changes to the database schema and data. @@ -18,12 +18,12 @@ If a migration fails, the application will attempt to restore the databases from 1. Locate the Backup Files: - Find the _first_ failed migration attempt and note the associated ID (it will be in application logs). If it can't be located, it is safe to assume that the oldest ID is the correct one. - - Navigate to the `migrations` directory within the application's data directory. + - Navigate to the `backups` directory within the application's data directory. - Look for files named `<database>.pre-migration-backup.<migration id>.db`. 2. Restore the Backup: - Rename the backup file to replace the current database file. For example, rename `transfers.pre-migration-backup.040123_123456.db` to `transfers.db`. - - Ensure the restored file is placed in the root of the application's data directory (move it up, out of the `migrations` directory). + - Ensure the restored file is placed in the root of the application's data directory (move it up, out of the `backups` directory). 3. Restart the Application: - Start the application again. It will detect the restored database and attempt to reapply the migration. diff --git a/src/slskd/Core/Data/IMigration.cs b/src/slskd/Core/Data/IMigration.cs new file mode 100644 index 00000000..18b198b2 --- /dev/null +++ b/src/slskd/Core/Data/IMigration.cs @@ -0,0 +1,38 @@ +// <copyright file="IMigration.cs" company="slskd Team"> +// 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/. +// </copyright> + +namespace slskd; + +/// <summary> +/// Applies database migrations. +/// </summary> +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(); + + /// <summary> + /// Applies the migration. + /// </summary> + void Apply(); +}
\ No newline at end of file diff --git a/src/slskd/Core/Data/Migrations/README.md b/src/slskd/Core/Data/Migrations/README.md index e8630265..2b5fd6f4 100644 --- a/src/slskd/Core/Data/Migrations/README.md +++ b/src/slskd/Core/Data/Migrations/README.md @@ -27,6 +27,4 @@ Review the `IMigration` interface to determine implementation details. 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. - -Users can delete the history file or use the `force` flag to cause migrations to be run again. We can inspect schemas to determine whether re-running is necessary, but there may be cases where that's not enough.
\ No newline at end of file +### Above all else, each and every migration **MUST** be idempotent; they'll be evaluated and run each time the app starts.
\ No newline at end of file diff --git a/src/slskd/Core/Data/Migrator.cs b/src/slskd/Core/Data/Migrator.cs index 4cc56147..e359d334 100644 --- a/src/slskd/Core/Data/Migrator.cs +++ b/src/slskd/Core/Data/Migrator.cs @@ -28,26 +28,6 @@ using slskd.Migrations; /// <summary> /// Applies database migrations. /// </summary> -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(); - - /// <summary> - /// Applies the migration. - /// </summary> - void Apply(); -} - -/// <summary> -/// Applies database migrations. -/// </summary> public class Migrator { /// <summary> |
