mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-22 21:50:36 +02:00
Do not run DELETE command if no extras are detected
Also log a message if no extras were detected Also log the path used for the database backup Also add some comments to explain the migration
This commit is contained in:
parent
43dc604e87
commit
6e68702799
|
@ -39,11 +39,18 @@ namespace Jellyfin.Server.Migrations.Routines
|
||||||
ConnectionFlags.ReadWrite,
|
ConnectionFlags.ReadWrite,
|
||||||
null))
|
null))
|
||||||
{
|
{
|
||||||
|
// Query the database for the ids of duplicate extras
|
||||||
var queryResult = connection.Query("SELECT t1.Path FROM TypedBaseItems AS t1, TypedBaseItems AS t2 WHERE t1.Path=t2.Path AND t1.Type!=t2.Type AND t1.Type='MediaBrowser.Controller.Entities.Video'");
|
var queryResult = connection.Query("SELECT t1.Path FROM TypedBaseItems AS t1, TypedBaseItems AS t2 WHERE t1.Path=t2.Path AND t1.Type!=t2.Type AND t1.Type='MediaBrowser.Controller.Entities.Video'");
|
||||||
var bads = string.Join(", ", queryResult.SelectScalarString());
|
var bads = string.Join(", ", queryResult.SelectScalarString());
|
||||||
if (bads.Length != 0)
|
|
||||||
|
// Do nothing if no duplicate extras were detected
|
||||||
|
if (bads.Length == 0)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Found duplicate extras, making {Library} backup", DbFilename);
|
_logger.LogInformation("No duplicate extras detected, skipping migration.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Back up the database before deleting any entries
|
||||||
for (int i = 1; ; i++)
|
for (int i = 1; ; i++)
|
||||||
{
|
{
|
||||||
var bakPath = string.Format(CultureInfo.InvariantCulture, "{0}.bak{1}", dbPath, i);
|
var bakPath = string.Format(CultureInfo.InvariantCulture, "{0}.bak{1}", dbPath, i);
|
||||||
|
@ -52,20 +59,21 @@ namespace Jellyfin.Server.Migrations.Routines
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Copy(dbPath, bakPath);
|
File.Copy(dbPath, bakPath);
|
||||||
|
_logger.LogInformation("Library database backed up to {BackupPath}", bakPath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Cannot make a backup of {Library}", DbFilename);
|
_logger.LogError(ex, "Cannot make a backup of {Library} at path {BackupPath}", DbFilename, bakPath);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete all duplicate extras
|
||||||
_logger.LogInformation("Removing found duplicated extras for the following items: {DuplicateExtras}", bads);
|
_logger.LogInformation("Removing found duplicated extras for the following items: {DuplicateExtras}", bads);
|
||||||
connection.Execute("DELETE FROM TypedBaseItems WHERE rowid IN (SELECT t1.rowid FROM TypedBaseItems AS t1, TypedBaseItems AS t2 WHERE t1.Path=t2.Path AND t1.Type!=t2.Type AND t1.Type='MediaBrowser.Controller.Entities.Video')");
|
connection.Execute("DELETE FROM TypedBaseItems WHERE rowid IN (SELECT t1.rowid FROM TypedBaseItems AS t1, TypedBaseItems AS t2 WHERE t1.Path=t2.Path AND t1.Type!=t2.Type AND t1.Type='MediaBrowser.Controller.Entities.Video')");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue