diff --git a/SUMMARY.md b/SUMMARY.md index dd6336b..939d02f 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -1,20 +1,51 @@ # NFOGuard Development Summary -## Current Status: v1.3.2 - Path Mapping Fix & Database Migration +## Current Status: v1.3.4 - Complete Database Migration Fix -### Latest Updates (v1.3.2) -- **🐛 CRITICAL**: Fixed path mapping bug converting `movies6` to `movies/6` -- **🔧 DATABASE**: Added automatic migration for `has_video_file` columns -- **🎯 PATH CONFIG**: Removed all hardcoded paths - fully configurable via environment -- **📝 VALIDATION**: Enhanced path validation in webhook processing -- **🔍 DEBUG**: Added debug logging to path mapper for troubleshooting +### Latest Updates (v1.3.4) +- **🔧 DATABASE**: Fixed comprehensive schema migration for all missing columns +- **✅ MIGRATION**: Added automatic detection and addition of `path`, `has_video_file`, `last_updated` columns +- **🎯 ROBUST**: Schema introspection ensures all required columns exist +- **🔍 VALIDATION**: Comprehensive column checking for both movies and episodes tables -### Path Mapping Logic (Fixed) +### Database Migration Strategy +``` +✅ Check existing schema with PRAGMA table_info() +✅ Add missing columns: path, has_video_file, last_updated +✅ Update existing records with default values +✅ Handle both movies and episodes tables +✅ Graceful migration without data loss +``` + +### Path Mapping Success (v1.3.2-v1.3.4) +- **🐛 CRITICAL**: Fixed substring matching bug (movies/movies6, tv/tv6) +- **🎯 ALGORITHM**: Longest-path-first matching prevents incorrect mappings +- **📝 DEBUG**: Comprehensive debug logging for troubleshooting +- **✅ TESTED**: Annabelle webhook processes correctly through all stageslopment Summary + +## Current Status: v1.3.3 - Database Migration & Path Validation Complete + +### Latest Updates (v1.3.3) +- **� DATABASE**: Fixed missing `path` column migration in movies table +- **✅ MIGRATION**: Automatic schema updates with graceful error handling +- **🔍 VALIDATION**: Enhanced database migration with column existence checks +- **🎯 COMPATIBILITY**: Backward compatibility with existing databases maintained + +### Path Mapping Success (v1.3.2-v1.3.3) +- **🐛 CRITICAL**: Fixed substring matching bug (movies/movies6, tv/tv6) +- **🎯 ALGORITHM**: Longest-path-first matching prevents incorrect mappings +- **� DEBUG**: Comprehensive debug logging for troubleshooting +- **✅ TESTED**: Annabelle webhook now processes correctly + +### Working Path Mapping Example ``` Radarr webhook: /mnt/unionfs/Media/Movies/movies6/Annabelle... -↓ Match RADARR_ROOT_FOLDERS[1]: /mnt/unionfs/Media/Movies/movies6 -↓ Map to MOVIE_PATHS[1]: /media/Movies/movies6 -✅ Result: /media/Movies/movies6/Annabelle... +✅ Sort by length: [movies6, movies] (longest first) +✅ Match movies6: /mnt/unionfs/Media/Movies/movies6 +✅ Map to index 1: /media/Movies/movies6 +✅ Result: /media/Movies/movies6/Annabelle (2014) [tt3322940] +✅ Path exists: Validation passes +✅ Processing: Movie webhook succeeds ``` ### Environment Configuration Required diff --git a/VERSION b/VERSION index 1892b92..d0149fe 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.2 +1.3.4 diff --git a/core/database.py b/core/database.py index bff89c7..017e0f9 100644 --- a/core/database.py +++ b/core/database.py @@ -97,29 +97,32 @@ class NFOGuardDatabase: """) # Add missing columns if they don't exist (migration) - try: - cursor.execute("ALTER TABLE episodes ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE") - except sqlite3.OperationalError: - # Column already exists - pass - - try: - cursor.execute("ALTER TABLE movies ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE") - except sqlite3.OperationalError: - # Column already exists - pass - - # Check if movies table has path column, add if missing + # Check current schema and add missing columns cursor.execute("PRAGMA table_info(movies)") - columns = [row[1] for row in cursor.fetchall()] - if 'path' not in columns: + movie_columns = [row[1] for row in cursor.fetchall()] + + cursor.execute("PRAGMA table_info(episodes)") + episode_columns = [row[1] for row in cursor.fetchall()] + + # Add missing columns to movies table + if 'path' not in movie_columns: cursor.execute("ALTER TABLE movies ADD COLUMN path TEXT") - # Update existing records with a placeholder path cursor.execute("UPDATE movies SET path = '/unknown/path/' || imdb_id WHERE path IS NULL") - - # Make path NOT NULL after adding it - # Note: SQLite doesn't support ALTER COLUMN, so we'd need to recreate table - # For now, just ensure new records have paths + + if 'has_video_file' not in movie_columns: + cursor.execute("ALTER TABLE movies ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE") + + if 'last_updated' not in movie_columns: + cursor.execute("ALTER TABLE movies ADD COLUMN last_updated TEXT") + cursor.execute("UPDATE movies SET last_updated = datetime('now') WHERE last_updated IS NULL") + + # Add missing columns to episodes table + if 'has_video_file' not in episode_columns: + cursor.execute("ALTER TABLE episodes ADD COLUMN has_video_file BOOLEAN DEFAULT FALSE") + + if 'last_updated' not in episode_columns: + cursor.execute("ALTER TABLE episodes ADD COLUMN last_updated TEXT") + cursor.execute("UPDATE episodes SET last_updated = datetime('now') WHERE last_updated IS NULL") # Create indexes cursor.execute("CREATE INDEX IF NOT EXISTS idx_episodes_imdb ON episodes(imdb_id)")