Browse Source

delete orphan plex media sources (#85)

* delete orphan plex media sources

* fix plex db warning on startup
pull/86/head
Jason Dove 5 years ago committed by GitHub
parent
commit
493a496b91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs
  2. 1686
      ErsatzTV.Infrastructure/Migrations/20210319010444_Delete_OrphanPlexMediaSources.Designer.cs
  3. 16
      ErsatzTV.Infrastructure/Migrations/20210319010444_Delete_OrphanPlexMediaSources.cs
  4. 2
      ErsatzTV.Infrastructure/Migrations/TvContextModelSnapshot.cs

15
ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs

@ -107,14 +107,19 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @@ -107,14 +107,19 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.Map(Optional);
}
public Task<Option<PlexMediaSource>> GetPlexByLibraryId(int plexLibraryId)
public async Task<Option<PlexMediaSource>> GetPlexByLibraryId(int plexLibraryId)
{
using TvContext context = _dbContextFactory.CreateDbContext();
return context.PlexMediaSources
int? id = await _dbConnection.QuerySingleAsync<int?>(
@"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.Libraries)
.Where(p => p.Libraries.Any(l => l.Id == plexLibraryId))
.SingleOrDefaultAsync()
.OrderBy(p => p.Id)
.SingleOrDefaultAsync(p => p.Id == id)
.Map(Optional);
}

1686
ErsatzTV.Infrastructure/Migrations/20210319010444_Delete_OrphanPlexMediaSources.Designer.cs generated

File diff suppressed because it is too large Load Diff

16
ErsatzTV.Infrastructure/Migrations/20210319010444_Delete_OrphanPlexMediaSources.cs

@ -0,0 +1,16 @@ @@ -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)
{
}
}
}

2
ErsatzTV.Infrastructure/Migrations/TvContextModelSnapshot.cs

@ -14,7 +14,7 @@ namespace ErsatzTV.Infrastructure.Migrations @@ -14,7 +14,7 @@ namespace ErsatzTV.Infrastructure.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.3");
.HasAnnotation("ProductVersion", "5.0.4");
modelBuilder.Entity(
"ErsatzTV.Core.Domain.Artwork",

Loading…
Cancel
Save