|
| 1 | +--- |
| 2 | +title: DecentDB Usage & Migration |
| 3 | +description: How Melodee uses DecentDB, how to diagnose compatibility issues, and how to rebuild generated DecentDB search databases. |
| 4 | +permalink: /decentdb/ |
| 5 | +tags: |
| 6 | + - decentdb |
| 7 | + - migration |
| 8 | + - troubleshooting |
| 9 | +--- |
| 10 | + |
| 11 | +## Overview |
| 12 | + |
| 13 | +Melodee uses DecentDB for local, generated search databases. These files are |
| 14 | +separate from the primary Melodee PostgreSQL database and can be rebuilt from |
| 15 | +source data when necessary. |
| 16 | + |
| 17 | +DecentDB is currently used for: |
| 18 | + |
| 19 | +- **MusicBrainz search data**: the local MusicBrainz artist, alias, relation, |
| 20 | + and album lookup database. |
| 21 | +- **Artist search cache**: the local artist search repository used to speed up |
| 22 | + artist matching and enrichment. |
| 23 | + |
| 24 | +Melodee does not store user accounts, playlists, play history, ratings, or |
| 25 | +library metadata in these DecentDB files. Those records live in the primary |
| 26 | +PostgreSQL database. |
| 27 | + |
| 28 | +## Configuration |
| 29 | + |
| 30 | +The DecentDB databases are configured with these connection strings: |
| 31 | + |
| 32 | +| Connection string | Purpose | |
| 33 | +|-------------------|---------| |
| 34 | +| `MusicBrainzConnection` | Local MusicBrainz lookup database | |
| 35 | +| `ArtistSearchEngineConnection` | Local artist search cache database | |
| 36 | + |
| 37 | +In container deployments, the same values can be supplied with environment |
| 38 | +variables: |
| 39 | + |
| 40 | +```bash |
| 41 | +ConnectionStrings__MusicBrainzConnection="Data Source=/app/storage/_search-engines/musicbrainz/musicbrainz.ddb" |
| 42 | +ConnectionStrings__ArtistSearchEngineConnection="Data Source=/app/storage/_search-engines/artistSearchEngine.ddb" |
| 43 | +``` |
| 44 | + |
| 45 | +Use your configured paths as the source of truth. Older installations may use |
| 46 | +`.db` filenames while newer examples use `.ddb`; the connection string path is |
| 47 | +what matters. |
| 48 | + |
| 49 | +## Doctor Compatibility Checks |
| 50 | + |
| 51 | +Doctor opens both DecentDB files with the current Melodee DecentDB provider. If |
| 52 | +the file was created by a newer or incompatible DecentDB engine, Doctor reports |
| 53 | +an issue similar to: |
| 54 | + |
| 55 | +```text |
| 56 | +MusicBrainz DecentDB database uses a file format that is not supported by the current DecentDB provider. |
| 57 | +Provider error: unsupported DecentDB file format version 11 |
| 58 | +``` |
| 59 | + |
| 60 | +This means the current Melodee process cannot safely read that generated search |
| 61 | +database. Search and enrichment may continue in degraded mode, but the affected |
| 62 | +database should be rebuilt or the Melodee/DecentDB package version should be |
| 63 | +updated. |
| 64 | + |
| 65 | +## Migration Strategy |
| 66 | + |
| 67 | +For Melodee's generated DecentDB files, migration usually means rebuilding the |
| 68 | +affected generated database with the current Melodee version. This is safer than |
| 69 | +trying to manually edit a DecentDB file created by an incompatible provider. |
| 70 | + |
| 71 | +Use this order: |
| 72 | + |
| 73 | +1. Upgrade Melodee to the intended version. |
| 74 | +2. Stop Melodee so no process is writing to the DecentDB files. |
| 75 | +3. Back up the affected `.ddb` file and any companion WAL or shared-memory |
| 76 | + files. |
| 77 | +4. Move the incompatible generated database out of the active path. |
| 78 | +5. Start Melodee. |
| 79 | +6. Rebuild the affected database from Melodee. |
| 80 | +7. Run Doctor again and confirm the DecentDB checks pass. |
| 81 | + |
| 82 | +## Backup Before Rebuild |
| 83 | + |
| 84 | +Back up the main database and generated DecentDB files before changing anything. |
| 85 | +The example below preserves common DecentDB companion file names. |
| 86 | + |
| 87 | +```bash |
| 88 | +#!/usr/bin/env bash |
| 89 | +set -euo pipefail |
| 90 | + |
| 91 | +backup_root="$HOME/melodee-decentdb-backup-$(date +%Y%m%d-%H%M%S)" |
| 92 | +mkdir -p "$backup_root" |
| 93 | + |
| 94 | +musicbrainz_db="/path/to/search-engine-storage/musicbrainz/musicbrainz.ddb" |
| 95 | +artist_search_db="/path/to/search-engine-storage/artistSearchEngine.ddb" |
| 96 | + |
| 97 | +backup_decentdb_file() { |
| 98 | + local db_path="$1" |
| 99 | + local db_name |
| 100 | + db_name="$(basename "$db_path")" |
| 101 | + |
| 102 | + for suffix in "" ".wal" "-wal" ".shm" "-shm"; do |
| 103 | + if [ -f "${db_path}${suffix}" ]; then |
| 104 | + cp -a "${db_path}${suffix}" "$backup_root/${db_name}${suffix}" |
| 105 | + fi |
| 106 | + done |
| 107 | +} |
| 108 | + |
| 109 | +backup_decentdb_file "$musicbrainz_db" |
| 110 | +backup_decentdb_file "$artist_search_db" |
| 111 | + |
| 112 | +echo "Backed up DecentDB files to $backup_root" |
| 113 | +``` |
| 114 | + |
| 115 | +Also back up PostgreSQL before a Melodee upgrade. See |
| 116 | +[Backup & Recovery](/backup/) for full backup guidance. |
| 117 | + |
| 118 | +## Example: Rebuild Incompatible DecentDB Files |
| 119 | + |
| 120 | +This example renames incompatible generated DecentDB files so Melodee can create |
| 121 | +fresh files with the current provider. |
| 122 | + |
| 123 | +```bash |
| 124 | +#!/usr/bin/env bash |
| 125 | +set -euo pipefail |
| 126 | + |
| 127 | +stamp="$(date +%Y%m%d-%H%M%S)" |
| 128 | + |
| 129 | +musicbrainz_db="/path/to/search-engine-storage/musicbrainz/musicbrainz.ddb" |
| 130 | +artist_search_db="/path/to/search-engine-storage/artistSearchEngine.ddb" |
| 131 | + |
| 132 | +move_decentdb_file_aside() { |
| 133 | + local db_path="$1" |
| 134 | + |
| 135 | + for suffix in "" ".wal" "-wal" ".shm" "-shm"; do |
| 136 | + if [ -f "${db_path}${suffix}" ]; then |
| 137 | + mv "${db_path}${suffix}" "${db_path}${suffix}.unsupported-$stamp" |
| 138 | + fi |
| 139 | + done |
| 140 | +} |
| 141 | + |
| 142 | +# Stop Melodee before moving active database files. |
| 143 | +# podman compose down |
| 144 | +# docker compose down |
| 145 | + |
| 146 | +move_decentdb_file_aside "$musicbrainz_db" |
| 147 | +move_decentdb_file_aside "$artist_search_db" |
| 148 | + |
| 149 | +# Start Melodee again. |
| 150 | +# podman compose up -d |
| 151 | +# docker compose up -d |
| 152 | +``` |
| 153 | + |
| 154 | +After the files are moved aside, rebuild the generated databases. |
| 155 | + |
| 156 | +### MusicBrainz |
| 157 | + |
| 158 | +Use one of these options: |
| 159 | + |
| 160 | +- In the web UI, go to **Admin > Doctor** and use **Generate MusicBrainz |
| 161 | + Database**. |
| 162 | +- In the web UI, go to **Admin > Jobs** and run |
| 163 | + `MusicBrainzUpdateDatabaseJob`. |
| 164 | +- From the CLI, run: |
| 165 | + |
| 166 | +```bash |
| 167 | +./mcli job musicbrainz-update |
| 168 | +``` |
| 169 | + |
| 170 | +MusicBrainz rebuilds can take a long time because Melodee downloads and imports |
| 171 | +the MusicBrainz dump into a local DecentDB file. |
| 172 | + |
| 173 | +### Artist Search Cache |
| 174 | + |
| 175 | +Use one of these options: |
| 176 | + |
| 177 | +- In the web UI, go to **Admin > Jobs** and run |
| 178 | + `ArtistSearchEngineRepositoryHousekeepingJob`. |
| 179 | +- From the CLI, run: |
| 180 | + |
| 181 | +```bash |
| 182 | +./mcli job artistsearchengine-refresh |
| 183 | +``` |
| 184 | + |
| 185 | +The artist search cache is generated from Melodee's library data and configured |
| 186 | +artist search providers. It can be rebuilt after the incompatible file is moved |
| 187 | +aside. |
| 188 | + |
| 189 | +## Verify The Migration |
| 190 | + |
| 191 | +Run Doctor after rebuilding: |
| 192 | + |
| 193 | +```bash |
| 194 | +./mcli doctor --verbose |
| 195 | +``` |
| 196 | + |
| 197 | +Or open **Admin > Doctor** in the web UI. |
| 198 | + |
| 199 | +The following checks should pass: |
| 200 | + |
| 201 | +- `MusicBrainzDatabase` |
| 202 | +- `ArtistSearchEngineDatabase` |
| 203 | + |
| 204 | +If Doctor still reports an unsupported DecentDB file format after rebuilding, |
| 205 | +confirm that: |
| 206 | + |
| 207 | +- Melodee is running the version you expect. |
| 208 | +- The active connection strings point to the rebuilt files. |
| 209 | +- No old `.wal`, `-wal`, `.shm`, or `-shm` companion files remain beside the |
| 210 | + rebuilt database. |
| 211 | +- The app container or service was restarted after the rebuild. |
| 212 | + |
| 213 | +## What Not To Delete |
| 214 | + |
| 215 | +Do not delete the primary PostgreSQL database when resolving DecentDB search |
| 216 | +cache compatibility issues. The unsupported DecentDB file-format warning applies |
| 217 | +to generated local search databases, not the primary Melodee database. |
| 218 | + |
0 commit comments