delete orphan plex media sources (#85)
* delete orphan plex media sources * fix plex db warning on startup
This commit is contained in:
@@ -107,14 +107,19 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
|
|||||||
.Map(Optional);
|
.Map(Optional);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Option<PlexMediaSource>> GetPlexByLibraryId(int plexLibraryId)
|
public async Task<Option<PlexMediaSource>> GetPlexByLibraryId(int plexLibraryId)
|
||||||
{
|
{
|
||||||
using TvContext context = _dbContextFactory.CreateDbContext();
|
int? id = await _dbConnection.QuerySingleAsync<int?>(
|
||||||
return context.PlexMediaSources
|
@"SELECT L.MediaSourceId FROM Library L
|
||||||
|
INNER JOIN PlexLibrary PL on L.Id = PL.Id
|
||||||
|
WHERE L.Id = @PlexLibraryId", new { PlexLibraryId = plexLibraryId });
|
||||||
|
|
||||||
|
await using TvContext context = _dbContextFactory.CreateDbContext();
|
||||||
|
return await context.PlexMediaSources
|
||||||
.Include(p => p.Connections)
|
.Include(p => p.Connections)
|
||||||
.Include(p => p.Libraries)
|
.Include(p => p.Libraries)
|
||||||
.Where(p => p.Libraries.Any(l => l.Id == plexLibraryId))
|
.OrderBy(p => p.Id)
|
||||||
.SingleOrDefaultAsync()
|
.SingleOrDefaultAsync(p => p.Id == id)
|
||||||
.Map(Optional);
|
.Map(Optional);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Generated
+1686
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,16 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
public partial class Delete_OrphanPlexMediaSources : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder) =>
|
||||||
|
migrationBuilder.Sql(
|
||||||
|
@"DELETE FROM MediaSource WHERE Id NOT IN
|
||||||
|
(SELECT Id FROM LocalMediaSource UNION ALL SELECT Id FROM PlexMediaSource)");
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ namespace ErsatzTV.Infrastructure.Migrations
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "5.0.3");
|
.HasAnnotation("ProductVersion", "5.0.4");
|
||||||
|
|
||||||
modelBuilder.Entity(
|
modelBuilder.Entity(
|
||||||
"ErsatzTV.Core.Domain.Artwork",
|
"ErsatzTV.Core.Domain.Artwork",
|
||||||
|
|||||||
Reference in New Issue
Block a user