aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs
diff options
context:
space:
mode:
authorcvium <clausvium@gmail.com>2023-08-21 15:31:02 +0200
committercvium <clausvium@gmail.com>2023-08-21 15:31:02 +0200
commitd223f5b5186f89ff9c6e931ae2341b44b190946d (patch)
treec464958c37debfefabfff068ba1777e9ea954958 /Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs
parent061d79c113404359068e94256104f955720bd1eb (diff)
completely remove sqlitepcl
Diffstat (limited to 'Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs')
-rw-r--r--Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs49
1 files changed, 22 insertions, 27 deletions
diff --git a/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs
index 5f44ba2ca..c7c9c1250 100644
--- a/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs
+++ b/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs
@@ -3,12 +3,11 @@ using System.Collections.Generic;
using System.IO;
using Emby.Server.Implementations.Data;
using Jellyfin.Data.Entities;
-using Jellyfin.Server.Extensions;
using Jellyfin.Server.Implementations;
using MediaBrowser.Controller;
+using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
-using SQLitePCL.pretty;
namespace Jellyfin.Server.Migrations.Routines
{
@@ -62,17 +61,12 @@ namespace Jellyfin.Server.Migrations.Routines
};
var dataPath = _paths.DataPath;
- using (var connection = SQLite3.Open(
- Path.Combine(dataPath, DbFilename),
- ConnectionFlags.ReadOnly,
- null))
+ using (var connection = new SqliteConnection($"Filename={Path.Combine(dataPath, DbFilename)}"))
{
- using var userDbConnection = SQLite3.Open(Path.Combine(dataPath, "users.db"), ConnectionFlags.ReadOnly, null);
+ using var userDbConnection = new SqliteConnection($"Filename={Path.Combine(dataPath, "users.db")}");
_logger.LogWarning("Migrating the activity database may take a while, do not stop Jellyfin.");
using var dbContext = _provider.CreateDbContext();
- var queryResult = connection.Query("SELECT * FROM ActivityLog ORDER BY Id");
-
// Make sure that the database is empty in case of failed migration due to power outages, etc.
dbContext.ActivityLogs.RemoveRange(dbContext.ActivityLogs);
dbContext.SaveChanges();
@@ -82,51 +76,52 @@ namespace Jellyfin.Server.Migrations.Routines
var newEntries = new List<ActivityLog>();
+ var queryResult = connection.Query("SELECT * FROM ActivityLog ORDER BY Id");
+
foreach (var entry in queryResult)
{
- if (!logLevelDictionary.TryGetValue(entry[8].ToString(), out var severity))
+ if (!logLevelDictionary.TryGetValue(entry.GetString(8), out var severity))
{
severity = LogLevel.Trace;
}
var guid = Guid.Empty;
- if (entry[6].SQLiteType != SQLiteType.Null && !Guid.TryParse(entry[6].ToString(), out guid))
+ if (!entry.IsDBNull(6) && !entry.TryGetGuid(6, out guid))
{
+ var id = entry.GetString(6);
// This is not a valid Guid, see if it is an internal ID from an old Emby schema
- _logger.LogWarning("Invalid Guid in UserId column: {Guid}", entry[6].ToString());
+ _logger.LogWarning("Invalid Guid in UserId column: {Guid}", id);
using var statement = userDbConnection.PrepareStatement("SELECT guid FROM LocalUsersv2 WHERE Id=@Id");
- statement.TryBind("@Id", entry[6].ToString());
+ statement.TryBind("@Id", id);
- foreach (var row in statement.Query())
+ using var reader = statement.ExecuteReader();
+ if (reader.HasRows && reader.Read() && reader.TryGetGuid(0, out guid))
{
- if (row.Count > 0 && Guid.TryParse(row[0].ToString(), out guid))
- {
- // Successfully parsed a Guid from the user table.
- break;
- }
+ // Successfully parsed a Guid from the user table.
+ break;
}
}
- var newEntry = new ActivityLog(entry[1].ToString(), entry[4].ToString(), guid)
+ var newEntry = new ActivityLog(entry.GetString(1), entry.GetString(4), guid)
{
- DateCreated = entry[7].ReadDateTime(),
+ DateCreated = entry.GetDateTime(7),
LogSeverity = severity
};
- if (entry[2].SQLiteType != SQLiteType.Null)
+ if (entry.TryGetString(2, out var result))
{
- newEntry.Overview = entry[2].ToString();
+ newEntry.Overview = result;
}
- if (entry[3].SQLiteType != SQLiteType.Null)
+ if (entry.TryGetString(3, out result))
{
- newEntry.ShortOverview = entry[3].ToString();
+ newEntry.ShortOverview = result;
}
- if (entry[5].SQLiteType != SQLiteType.Null)
+ if (entry.TryGetString(5, out result))
{
- newEntry.ItemId = entry[5].ToString();
+ newEntry.ItemId = result;
}
newEntries.Add(newEntry);