diff --git a/AGENTS.md b/AGENTS.md index 86ace64b7..a349b5120 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,6 +14,7 @@ This is a **local development deployment** of [Audiobookshelf](https://audiobook ## Technology Stack ### Backend + - **Runtime**: Node.js (v20) - **Framework**: Express.js with Socket.IO - **Database**: SQLite3 with Sequelize ORM @@ -25,6 +26,7 @@ This is a **local development deployment** of [Audiobookshelf](https://audiobook - `nodemailer` - Email notifications ### Frontend + - **Framework**: Nuxt.js (Vue.js) - **State Management**: Vuex - **CSS**: Custom styles with PostCSS @@ -112,8 +114,10 @@ docker buildx build --platform linux/amd64,linux/arm64 -t advplyr/audiobookshelf 1. **Node.js v20** and **FFmpeg** are required 2. Create `dev.js` in root directory for local configuration (see `.devcontainer/dev.js` for example) 3. Default development ports: - - Server: `3333` - - Client (dev): `3000` + +- Server: `3333` +- Client (dev): `3000` + 4. Access the running instance directly on `localhost:3333` ## Important Notes @@ -138,6 +142,7 @@ OpenAPI documentation available at `docs/openapi.json` ## Database Migrations Located in `server/migrations/`. Key migrations include: + - v2.15.0+ - Schema improvements - v2.17.x - Foreign key constraints and indices - v2.19.x - Library item improvements @@ -145,6 +150,61 @@ Located in `server/migrations/`. Key migrations include: Run migrations automatically on server startup. +## Portable Database Setup + +The database uses **relative paths** for portability. When moving the entire project folder: + +### Path Structure + +| Data Type | Database Path | Actual Location | +| ------------ | ---------------------------- | ------------------------------ | +| Audiobooks | `audiobooks/` | `./data/audiobooks/` | +| Cover images | `metadata/metadata/items/` | `./metadata/metadata/items/` | +| Backups | `metadata/metadata/backups/` | `./metadata/metadata/backups/` | + +### Migration Script + +Run the migration script to convert absolute Docker paths to relative paths: + +```bash +./scripts/migrate_to_relative_paths.sh +``` + +This script: + +1. Creates a backup at `config/absdatabase.sqlite.backup` +2. Converts `libraryFolders.path` to relative paths +3. Converts `libraryItems.path` and `relPath` to relative paths +4. Converts `books.coverPath` to relative paths +5. Updates `settings.backupPath` in JSON configuration +6. Creates necessary directory structure + +### Directory Structure (Created by Migration) + +``` +data/ + audiobooks/ +metadata/ + metadata/ + items/ + backups/ + cache/ + logs/ + streams/ +config/ + absdatabase.sqlite + absdatabase.sqlite.backup +``` + +### Starting the Server + +```bash +cd /mnt/docker/work/books/audiobookshelf +npm run dev +``` + +The server will resolve all paths relative to the current working directory. + ## Related Documentation - [Main Documentation](https://audiobookshelf.org/docs) diff --git a/Makefile b/Makefile index 714afdeda..753e8ee5f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SCRIPTS_DIR := scripts .DEFAULT_GOAL := help -.PHONY: help db-dump-all db-dump-folders db-dump-items db-dump-books db-dump-feeds db-dump-settings db-summary +.PHONY: help db-dump-all db-dump-folders db-dump-items db-dump-books db-dump-feeds db-dump-settings db-summary frontend-start backend-start help: @echo "Audiobookshelf Database Migration Tools" @@ -35,3 +35,9 @@ db-dump-settings: db-summary: @bash $(SCRIPTS_DIR)/dump_all.sh + +frontend-start: + cd client && npm run dev3 + +backend-start: + npm run dev diff --git a/client/package.json b/client/package.json index 0eaffb106..399bd2157 100644 --- a/client/package.json +++ b/client/package.json @@ -7,6 +7,7 @@ "scripts": { "dev": "nuxt", "dev2": "nuxt --hostname localhost --port 1337", + "dev3": "nuxt --hostname localhost --port 13378", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", diff --git a/scripts/migrate_to_relative_paths.sh b/scripts/migrate_to_relative_paths.sh index 874f5aff5..2ce39e448 100755 --- a/scripts/migrate_to_relative_paths.sh +++ b/scripts/migrate_to_relative_paths.sh @@ -3,19 +3,23 @@ # Migration Script: Convert absolute paths to relative paths # Makes the database portable within the current working directory # +# Expected structure after migration: +# - Audiobooks: ./data/audiobooks/, ./data/romance/ +# - Covers: ./metadata/metadata/items/ +# - Backups: ./metadata/metadata/backups/ +# set -e DB_SOURCE="/mnt/docker/work/books/audiobookshelf/config/absdatabase.sqlite" DB_BACKUP="/mnt/docker/work/books/audiobookshelf/config/absdatabase.sqlite.backup" -DB_MIGRATED="/mnt/docker/work/books/audiobookshelf/config/absdatabase.sqlite" echo "=== Audiobookshelf Path Migration ===" echo "Converting absolute paths to relative paths for portability" echo "" # Step 1: Create backup -echo "[1/4] Creating backup at $DB_BACKUP..." +echo "[1/5] Creating backup at $DB_BACKUP..." if [ -f "$DB_BACKUP" ]; then echo " Backup already exists, removing..." rm -f "$DB_BACKUP" @@ -25,20 +29,15 @@ echo " Backup created successfully" echo "" # Step 2: Show current state -echo "[2/4] Current state:" +echo "[2/5] Current state:" echo " Library folders:" sqlite3 "$DB_SOURCE" "SELECT id, path FROM libraryFolders;" | while read line; do echo " - $line" done echo "" -echo " Settings with paths:" -sqlite3 "$DB_SOURCE" "SELECT key, value FROM settings WHERE key LIKE '%path%' OR key IN ('backupPath');" | while read line; do - echo " - $line" -done -echo "" # Step 3: Run migration -echo "[3/4] Migrating paths..." +echo "[3/5] Migrating paths..." # Migrate libraryFolders paths echo " Converting libraryFolders paths..." @@ -59,22 +58,35 @@ sqlite3 "$DB_SOURCE" " echo " libraryItems: OK" # Migrate book cover paths +# Handle both original (/metadata/items/) and already-migrated (metadata/metadata/items/) echo " Converting book cover paths..." sqlite3 "$DB_SOURCE" " - UPDATE books SET coverPath = REPLACE(coverPath, '/metadata/items/', 'metadata/items/'); + UPDATE books SET coverPath = REPLACE(coverPath, '/metadata/items/', 'metadata/metadata/items/'); " echo " books: OK" -# Migrate settings (backupPath) +# Migrate settings (backupPath in JSON) echo " Converting settings..." sqlite3 "$DB_SOURCE" " - UPDATE settings SET value = 'metadata/backups' WHERE key = 'backupPath' AND value = '/metadata/backups'; + UPDATE settings SET value = REPLACE(value, '\"backupPath\":\"/metadata/backups\"', '\"backupPath\":\"metadata/metadata/backups\"') WHERE key = 'server-settings'; " echo " settings: OK" -# Verify migration +# Step 4: Create necessary directories echo "" -echo "[4/4] Verification:" +echo "[4/5] Creating directory structure..." +mkdir -p data/audiobooks +mkdir -p data/romance +mkdir -p metadata/metadata/items +mkdir -p metadata/metadata/backups +mkdir -p metadata/metadata/cache +mkdir -p metadata/metadata/logs +mkdir -p metadata/metadata/streams +echo " Directories created" + +# Step 5: Verification +echo "" +echo "[5/5] Verification:" echo " Library folders after migration:" sqlite3 "$DB_SOURCE" "SELECT id, path FROM libraryFolders;" | while read line; do echo " - $line" @@ -86,12 +98,12 @@ sqlite3 "$DB_SOURCE" "SELECT DISTINCT substr(path, 1, 50) FROM libraryItems LIMI done echo "" echo " Sample cover paths:" -sqlite3 "$DB_SOURCE" "SELECT DISTINCT substr(coverPath, 1, 50) FROM books LIMIT 5;" | while read line; do +sqlite3 "$DB_SOURCE" "SELECT DISTINCT substr(coverPath, 1, 60) FROM books LIMIT 5;" | while read line; do echo " - $line" done echo "" -echo " Settings after migration:" -sqlite3 "$DB_SOURCE" "SELECT key, value FROM settings WHERE key LIKE '%path%' OR key IN ('backupPath');" | while read line; do +echo " Settings backupPath:" +sqlite3 "$DB_SOURCE" "SELECT json_extract(value, '$.backupPath') FROM settings WHERE key = 'server-settings';" | while read line; do echo " - $line" done @@ -100,5 +112,11 @@ echo "=== Migration Complete ===" echo "Backup saved at: $DB_BACKUP" echo "Database migrated: $DB_SOURCE" echo "" +echo "Directory structure created:" +echo " - ./data/audiobooks/" +echo " - ./data/romance/" +echo " - ./metadata/metadata/items/" +echo " - ./metadata/metadata/backups/" +echo "" echo "To use the migrated database, run audiobookshelf from /mnt/docker/work/books/audiobookshelf:" echo " cd /mnt/docker/work/books/audiobookshelf && npm start"