aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-05-25 17:56:35 -0500
committerGitHub <noreply@github.com>2025-05-25 17:56:35 -0500
commitf9cc90d97274aad7262a26f5b43696f47d821387 (patch)
tree083ea0dd1f3147c7f8e38a82e2df788562897c97 /docs
parent7b99d3339154972eed0f04beef5a91678e5a0efb (diff)
parent930df71e94dedd5de5267418c3e7666a86eea416 (diff)
downloadslskd-f9cc90d97274aad7262a26f5b43696f47d821387.tar.gz
Merge pull request #1343 from slskd/migrations
Add a system to perform database migrations
Diffstat (limited to 'docs')
-rw-r--r--docs/README.md6
-rw-r--r--docs/config.md2
-rw-r--r--docs/migrations.md44
3 files changed, 51 insertions, 1 deletions
diff --git a/docs/README.md b/docs/README.md
index ce8316a7..eb08d969 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -17,4 +17,8 @@
## Building slskd from Source
-### [Build](https://github.com/slskd/slskd/blob/master/docs/build.md) \ No newline at end of file
+### [Build](https://github.com/slskd/slskd/blob/master/docs/build.md)
+
+## Troubleshooting
+
+### [Migrations](https://github.com/slskd/slskd/blob/master/docs/migrations.md) \ No newline at end of file
diff --git a/docs/config.md b/docs/config.md
index 78d1db48..cf7fb9a3 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -1231,6 +1231,7 @@ Several additional feature flags are provided to change the application's runtim
| `--no-connect` | `SLSKD_NO_CONNECT` | Start the application, but don't connect to the server |
| `--no-share-scan` | `SLSKD_NO_SHARE_SCAN` | Don't perform a scan of shared directories on startup |
| `--force-share-scan` | `SLSKD_FORCE_SHARE_SCAN` | Force a scan of shared directories on startup |
+| `--force-migrations` | `SLSKD_FORCE_MIGRATIONS` | Force database migrations to be applied on startup |
| `--no-version-check` | `SLSKD_NO_VERSION_CHECK` | Don't perform a version check on startup |
| `--log-sql` | `SLSKD_LOG_SQL` | Log SQL queries generated by Entity Framework |
| `--volatile` | `SLSKD_VOLATILE` | Use volatile data storage (all data will be lost at shutdown) |
@@ -1247,6 +1248,7 @@ flags:
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/docs/migrations.md b/docs/migrations.md
new file mode 100644
index 00000000..2fec53bd
--- /dev/null
+++ b/docs/migrations.md
@@ -0,0 +1,44 @@
+# Database Migrations
+
+Database migrations are used to update the structure of the application's databases to support new features or improve functionality. These migrations are applied automatically when the application starts. If a migration fails, the application will attempt to restore the database to its pre-migration state using backups created before the migration process began.
+
+## Migration Process
+
+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 `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.
+
+At the start of each migration a unique `migration id` is generated. If anything goes wrong, this ID can be used to locate the backup files created before the error occured (as subsequent migration attempts/retries will generate new backups, which may contain partially applied migrations).
+
+## What to Do If a Migration Fails
+
+If a migration fails, the application will attempt to restore the databases from the backups created before the migration. However, if the automatic restoration process fails, you can manually recover your data by following these steps:
+
+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 `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 `backups` directory).
+
+3. Restart the Application:
+ - Start the application again. It will detect the restored database and attempt to reapply the migration.
+
+## If the Migration Continues to Fail
+
+If the application gets "stuck" in a reboot loop and can't complete migration(s) successfully, you will need to rename (or delete) the existing database files and allow the application to re-generate them.
+
+It should be possible to recover the old data, but the process will need to be manual. Create a GitHub issue and provide logs from the failing migration(s).
+
+## Preventing Migration Issues
+
+To minimize the risk of migration failures:
+
+- Ensure Sufficient Disk Space: Verify that there is enough disk space available for creating backups and applying migrations.
+- Avoid Interruptions: Do not stop the application while a migration is in progress.
+- Monitor Logs: Check the application logs for detailed information about the migration process and any errors encountered.
+