properly fix database upgrade (#489)
This commit is contained in:
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Fixed
|
||||||
|
- Properly fix database incompatibility introduced with v0.2.4-alpha and partially fixed with v0.2.5-alpha
|
||||||
|
- The proper fix requires rebuilding all playouts, which will happen on startup after upgrading
|
||||||
|
|
||||||
## [0.2.5-alpha] - 2021-11-21
|
## [0.2.5-alpha] - 2021-11-21
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -89,12 +89,6 @@ namespace ErsatzTV.Core.Scheduling
|
|||||||
playout.ProgramScheduleAnchors.Clear();
|
playout.ProgramScheduleAnchors.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this works around weird EF behavior
|
|
||||||
if (playout.Anchor?.NextStart.Year < 2021)
|
|
||||||
{
|
|
||||||
playout.Anchor = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sortedScheduleItems = playout.ProgramSchedule.Items.OrderBy(i => i.Index).ToList();
|
var sortedScheduleItems = playout.ProgramSchedule.Items.OrderBy(i => i.Index).ToList();
|
||||||
var collectionEnumerators = new Dictionary<CollectionKey, IMediaCollectionEnumerator>();
|
var collectionEnumerators = new Dictionary<CollectionKey, IMediaCollectionEnumerator>();
|
||||||
foreach ((CollectionKey collectionKey, List<MediaItem> mediaItems) in collectionMediaItems)
|
foreach ((CollectionKey collectionKey, List<MediaItem> mediaItems) in collectionMediaItems)
|
||||||
@@ -380,7 +374,8 @@ namespace ErsatzTV.Core.Scheduling
|
|||||||
&& a.MediaItemId == collectionKey.MediaItemId);
|
&& a.MediaItemId == collectionKey.MediaItemId);
|
||||||
|
|
||||||
CollectionEnumeratorState state = maybeAnchor.Match(
|
CollectionEnumeratorState state = maybeAnchor.Match(
|
||||||
anchor => anchor.EnumeratorState,
|
anchor => anchor.EnumeratorState ??
|
||||||
|
(anchor.EnumeratorState = new CollectionEnumeratorState { Seed = Random.Next(), Index = 0 }),
|
||||||
() => new CollectionEnumeratorState { Seed = Random.Next(), Index = 0 });
|
() => new CollectionEnumeratorState { Seed = Random.Next(), Index = 0 });
|
||||||
|
|
||||||
if (await _mediaCollectionRepository.IsCustomPlaybackOrder(collectionKey.CollectionId ?? 0))
|
if (await _mediaCollectionRepository.IsCustomPlaybackOrder(collectionKey.CollectionId ?? 0))
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ namespace ErsatzTV.Infrastructure.Data.Configurations
|
|||||||
.HasForeignKey(pi => pi.PlayoutId)
|
.HasForeignKey(pi => pi.PlayoutId)
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
builder.OwnsOne(p => p.Anchor);
|
builder.OwnsOne(p => p.Anchor)
|
||||||
builder.Navigation(p => p.Anchor).IsRequired();
|
.ToTable("PlayoutAnchor");
|
||||||
|
|
||||||
builder.HasMany(p => p.ProgramScheduleAnchors)
|
builder.HasMany(p => p.ProgramScheduleAnchors)
|
||||||
.WithOne(a => a.Playout)
|
.WithOne(a => a.Playout)
|
||||||
|
|||||||
+1
-2
@@ -10,8 +10,7 @@ namespace ErsatzTV.Infrastructure.Data.Configurations
|
|||||||
{
|
{
|
||||||
builder.ToTable("PlayoutProgramScheduleAnchor");
|
builder.ToTable("PlayoutProgramScheduleAnchor");
|
||||||
|
|
||||||
builder.OwnsOne(a => a.EnumeratorState);
|
builder.OwnsOne(a => a.EnumeratorState).ToTable("CollectionEnumeratorState");
|
||||||
builder.Navigation(a => a.EnumeratorState).IsRequired();
|
|
||||||
|
|
||||||
builder.HasOne(i => i.Collection)
|
builder.HasOne(i => i.Collection)
|
||||||
.WithMany()
|
.WithMany()
|
||||||
|
|||||||
+3671
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,187 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
public partial class Move_ToOwnedTables : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Playout_ProgramScheduleItem_Anchor_NextScheduleItemId",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Playout_Anchor_NextScheduleItemId",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "EnumeratorState_Index",
|
||||||
|
table: "PlayoutProgramScheduleAnchor");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "EnumeratorState_Seed",
|
||||||
|
table: "PlayoutProgramScheduleAnchor");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Anchor_DurationFinish",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Anchor_InDurationFiller",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Anchor_InFlood",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Anchor_MultipleRemaining",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Anchor_NextGuideGroup",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Anchor_NextScheduleItemId",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Anchor_NextStart",
|
||||||
|
table: "Playout");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CollectionEnumeratorState",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
PlayoutProgramScheduleAnchorId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Seed = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Index = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CollectionEnumeratorState", x => x.PlayoutProgramScheduleAnchorId);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_CollectionEnumeratorState_PlayoutProgramScheduleAnchor_PlayoutProgramScheduleAnchorId",
|
||||||
|
column: x => x.PlayoutProgramScheduleAnchorId,
|
||||||
|
principalTable: "PlayoutProgramScheduleAnchor",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "PlayoutAnchor",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
PlayoutId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
NextScheduleItemId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
NextStart = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
MultipleRemaining = table.Column<int>(type: "INTEGER", nullable: true),
|
||||||
|
DurationFinish = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
InFlood = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||||
|
InDurationFiller = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||||
|
NextGuideGroup = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_PlayoutAnchor", x => x.PlayoutId);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PlayoutAnchor_Playout_PlayoutId",
|
||||||
|
column: x => x.PlayoutId,
|
||||||
|
principalTable: "Playout",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PlayoutAnchor_ProgramScheduleItem_NextScheduleItemId",
|
||||||
|
column: x => x.NextScheduleItemId,
|
||||||
|
principalTable: "ProgramScheduleItem",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayoutAnchor_NextScheduleItemId",
|
||||||
|
table: "PlayoutAnchor",
|
||||||
|
column: "NextScheduleItemId");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CollectionEnumeratorState");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "PlayoutAnchor");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "EnumeratorState_Index",
|
||||||
|
table: "PlayoutProgramScheduleAnchor",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "EnumeratorState_Seed",
|
||||||
|
table: "PlayoutProgramScheduleAnchor",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "Anchor_DurationFinish",
|
||||||
|
table: "Playout",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "Anchor_InDurationFiller",
|
||||||
|
table: "Playout",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "Anchor_InFlood",
|
||||||
|
table: "Playout",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "Anchor_MultipleRemaining",
|
||||||
|
table: "Playout",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "Anchor_NextGuideGroup",
|
||||||
|
table: "Playout",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "Anchor_NextScheduleItemId",
|
||||||
|
table: "Playout",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "Anchor_NextStart",
|
||||||
|
table: "Playout",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Playout_Anchor_NextScheduleItemId",
|
||||||
|
table: "Playout",
|
||||||
|
column: "Anchor_NextScheduleItemId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Playout_ProgramScheduleItem_Anchor_NextScheduleItemId",
|
||||||
|
table: "Playout",
|
||||||
|
column: "Anchor_NextScheduleItemId",
|
||||||
|
principalTable: "ProgramScheduleItem",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user