Browse Source

Backport pull request #15322 from jellyfin/release-10.11.z

Fix legacy migration file checks

Original-merge: da254ee968deca4d47f0f5d1164c5e883745ac60

Merged-by: crobibero <cody@robibe.ro>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
crobibero 2 weeks ago
parent
commit
c9d93b0745

+ 1 - 1
Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs

@@ -71,7 +71,7 @@ namespace Jellyfin.Server.Migrations.Routines
                     if (row.GetInt32(0) == 0)
                     if (row.GetInt32(0) == 0)
                     {
                     {
                         _logger.LogWarning("Table 'ActivityLog' doesn't exist in {ActivityLogPath}, nothing to migrate", activityLogPath);
                         _logger.LogWarning("Table 'ActivityLog' doesn't exist in {ActivityLogPath}, nothing to migrate", activityLogPath);
-                        break;
+                        return;
                     }
                     }
                 }
                 }
 
 

+ 20 - 1
Jellyfin.Server/Migrations/Routines/MigrateAuthenticationDb.cs

@@ -50,9 +50,28 @@ namespace Jellyfin.Server.Migrations.Routines
         public void Perform()
         public void Perform()
         {
         {
             var dataPath = _appPaths.DataPath;
             var dataPath = _appPaths.DataPath;
-            using (var connection = new SqliteConnection($"Filename={Path.Combine(dataPath, DbFilename)}"))
+            var dbFilePath = Path.Combine(dataPath, DbFilename);
+
+            if (!File.Exists(dbFilePath))
+            {
+                _logger.LogWarning("{Path} doesn't exist, nothing to migrate", dbFilePath);
+                return;
+            }
+
+            using (var connection = new SqliteConnection($"Filename={dbFilePath}"))
             {
             {
                 connection.Open();
                 connection.Open();
+
+                var tableQuery = connection.Query("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='Tokens';");
+                foreach (var row in tableQuery)
+                {
+                    if (row.GetInt32(0) == 0)
+                    {
+                        _logger.LogWarning("Table 'Tokens' doesn't exist in {Path}, nothing to migrate", dbFilePath);
+                        return;
+                    }
+                }
+
                 using var dbContext = _dbProvider.CreateDbContext();
                 using var dbContext = _dbProvider.CreateDbContext();
 
 
                 var authenticatedDevices = connection.Query("SELECT * FROM Tokens");
                 var authenticatedDevices = connection.Query("SELECT * FROM Tokens");

+ 18 - 0
Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs

@@ -78,9 +78,27 @@ namespace Jellyfin.Server.Migrations.Routines
             var displayPrefs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
             var displayPrefs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
             var customDisplayPrefs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
             var customDisplayPrefs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
             var dbFilePath = Path.Combine(_paths.DataPath, DbFilename);
             var dbFilePath = Path.Combine(_paths.DataPath, DbFilename);
+
+            if (!File.Exists(dbFilePath))
+            {
+                _logger.LogWarning("{Path} doesn't exist, nothing to migrate", dbFilePath);
+                return;
+            }
+
             using (var connection = new SqliteConnection($"Filename={dbFilePath}"))
             using (var connection = new SqliteConnection($"Filename={dbFilePath}"))
             {
             {
                 connection.Open();
                 connection.Open();
+
+                var tableQuery = connection.Query("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='userdisplaypreferences';");
+                foreach (var row in tableQuery)
+                {
+                    if (row.GetInt32(0) == 0)
+                    {
+                        _logger.LogWarning("Table 'userdisplaypreferences' doesn't exist in {Path}, nothing to migrate", dbFilePath);
+                        return;
+                    }
+                }
+
                 using var dbContext = _provider.CreateDbContext();
                 using var dbContext = _provider.CreateDbContext();
 
 
                 var results = connection.Query("SELECT * FROM userdisplaypreferences");
                 var results = connection.Query("SELECT * FROM userdisplaypreferences");

+ 1 - 1
Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs

@@ -75,7 +75,7 @@ public class MigrateUserDb : IMigrationRoutine
                 if (row.GetInt32(0) == 0)
                 if (row.GetInt32(0) == 0)
                 {
                 {
                     _logger.LogWarning("Table 'LocalUsersv2' doesn't exist in {UserDbPath}, nothing to migrate", userDbPath);
                     _logger.LogWarning("Table 'LocalUsersv2' doesn't exist in {UserDbPath}, nothing to migrate", userDbPath);
-                    break;
+                    return;
                 }
                 }
             }
             }