[DB] Update initial db

This commit is contained in:
max
2025-09-02 15:37:28 +02:00
parent dbf6938a7e
commit c30e503642
7 changed files with 125 additions and 48 deletions

View File

@@ -32,16 +32,21 @@ public sealed class LibraryDbContext : DbContext
{
channel.ToTable("channels");
channel.HasKey(x => x.Id);
//TODO: Link media from channel
channel.HasMany(x => x.Media)
.WithOne()
.HasForeignKey(x => x.ChannelId);
channel.HasMany(x => x.Playlists)
.WithOne()
.HasForeignKey(x => x.ChannelId);
channel.HasOne(x => x.ClientAccount)
.WithOne()
.HasForeignKey<ClientAccountEntity>(e => e.Id);
});
modelBuilder.Entity<ClientAccountEntity>(cae =>
{
cae.ToTable("client_accounts");
cae.HasKey(x => x.Id);
cae.HasMany(x => x.Playlists)
.WithOne()
.HasForeignKey(x => x.ChannelId);
cae.HasMany(x => x.HttpCookies)
.WithOne()
.HasForeignKey(x => x.ClientId);

View File

@@ -14,4 +14,7 @@ public class ChannelEntity : DateTimeBase
public long Subscribers { get; set; }
public long TotalVideos { get; set; }
public long TotalViews { get; set; }
public List<MediaEntity> Media { get; set; } = [];
public List<PlaylistEntity> Playlists { get; set; } = [];
public ClientAccountEntity? ClientAccount { get; set; }
}

View File

@@ -6,9 +6,6 @@ public class ClientAccountEntity : DateTimeBase
{
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public required string Id { get; set; }
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string Name { get; set; } = "";
public List<PlaylistEntity> Playlists { get; set; } = [];
public List<HttpCookieEntity> HttpCookies { get; set; } = [];
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
public string? UserAgent { get; set; }

View File

@@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Manager.Data.Migrations
{
[DbContext(typeof(LibraryDbContext))]
[Migration("20250831150411_initialLib")]
partial class initialLib
[Migration("20250902133345_InitialLibrary")]
partial class InitialLibrary
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -89,8 +89,7 @@ namespace Manager.Data.Migrations
b.Property<DateTime>("LastModifiedUtc")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
b.Property<string>("UserAgent")
.HasMaxLength(100)
.HasColumnType("TEXT");
@@ -210,6 +209,8 @@ namespace Manager.Data.Migrations
b.HasKey("Id");
b.HasIndex("ChannelId");
b.ToTable("media", (string)null);
});
@@ -318,6 +319,15 @@ namespace Manager.Data.Migrations
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
.WithOne("ClientAccount")
.HasForeignKey("Manager.Data.Entities.LibraryContext.ClientAccountEntity", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.HttpCookieEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
@@ -342,6 +352,15 @@ namespace Manager.Data.Migrations
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
.WithMany("Media")
.HasForeignKey("ChannelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaFormatEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
@@ -353,18 +372,25 @@ namespace Manager.Data.Migrations
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
.WithMany("Playlists")
.HasForeignKey("ChannelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ChannelEntity", b =>
{
b.Navigation("ClientAccount");
b.Navigation("Media");
b.Navigation("Playlists");
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
{
b.Navigation("HttpCookies");
b.Navigation("Playlists");
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>

View File

@@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Manager.Data.Migrations
{
/// <inheritdoc />
public partial class initialLib : Migration
public partial class InitialLibrary : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@@ -35,13 +35,19 @@ namespace Manager.Data.Migrations
columns: table => new
{
Id = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
UserAgent = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_client_accounts", x => x.Id);
table.ForeignKey(
name: "FK_client_accounts_channels_Id",
column: x => x.Id,
principalTable: "channels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@@ -62,6 +68,34 @@ namespace Manager.Data.Migrations
constraints: table =>
{
table.PrimaryKey("PK_media", x => x.Id);
table.ForeignKey(
name: "FK_media_channels_ChannelId",
column: x => x.ChannelId,
principalTable: "channels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "playlists",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
ChannelId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_playlists", x => x.Id);
table.ForeignKey(
name: "FK_playlists_channels_ChannelId",
column: x => x.ChannelId,
principalTable: "channels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@@ -91,28 +125,6 @@ namespace Manager.Data.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "playlists",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
ChannelId = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_playlists", x => x.Id);
table.ForeignKey(
name: "FK_playlists_client_accounts_ChannelId",
column: x => x.ChannelId,
principalTable: "client_accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "captions",
columns: table => new
@@ -201,6 +213,11 @@ namespace Manager.Data.Migrations
table: "join_playlist_media",
column: "MediaId");
migrationBuilder.CreateIndex(
name: "IX_media_ChannelId",
table: "media",
column: "ChannelId");
migrationBuilder.CreateIndex(
name: "IX_playlists_ChannelId",
table: "playlists",
@@ -213,9 +230,6 @@ namespace Manager.Data.Migrations
migrationBuilder.DropTable(
name: "captions");
migrationBuilder.DropTable(
name: "channels");
migrationBuilder.DropTable(
name: "http_cookies");
@@ -225,6 +239,9 @@ namespace Manager.Data.Migrations
migrationBuilder.DropTable(
name: "media_formats");
migrationBuilder.DropTable(
name: "client_accounts");
migrationBuilder.DropTable(
name: "playlists");
@@ -232,7 +249,7 @@ namespace Manager.Data.Migrations
name: "media");
migrationBuilder.DropTable(
name: "client_accounts");
name: "channels");
}
}
}

View File

@@ -86,8 +86,7 @@ namespace Manager.Data.Migrations
b.Property<DateTime>("LastModifiedUtc")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
b.Property<string>("UserAgent")
.HasMaxLength(100)
.HasColumnType("TEXT");
@@ -207,6 +206,8 @@ namespace Manager.Data.Migrations
b.HasKey("Id");
b.HasIndex("ChannelId");
b.ToTable("media", (string)null);
});
@@ -315,6 +316,15 @@ namespace Manager.Data.Migrations
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
.WithOne("ClientAccount")
.HasForeignKey("Manager.Data.Entities.LibraryContext.ClientAccountEntity", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.HttpCookieEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
@@ -339,6 +349,15 @@ namespace Manager.Data.Migrations
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
.WithMany("Media")
.HasForeignKey("ChannelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaFormatEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
@@ -350,18 +369,25 @@ namespace Manager.Data.Migrations
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
{
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
b.HasOne("Manager.Data.Entities.LibraryContext.ChannelEntity", null)
.WithMany("Playlists")
.HasForeignKey("ChannelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ChannelEntity", b =>
{
b.Navigation("ClientAccount");
b.Navigation("Media");
b.Navigation("Playlists");
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
{
b.Navigation("HttpCookies");
b.Navigation("Playlists");
});
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>

View File

@@ -12,4 +12,7 @@ Update the database
```shell
dotnet ef database update --project Manager.Data --startup-project Manager.App --context Manager.Data.Contexts.LibraryDbContext
```
Remove migration
```shell
dotnet ef migrations remove --project Manager.Data --startup-project Manager.App --context Manager.Data.Contexts.LibraryDbContext
```