[DB] Update initial db
This commit is contained in:
@@ -32,16 +32,21 @@ public sealed class LibraryDbContext : DbContext
|
|||||||
{
|
{
|
||||||
channel.ToTable("channels");
|
channel.ToTable("channels");
|
||||||
channel.HasKey(x => x.Id);
|
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 =>
|
modelBuilder.Entity<ClientAccountEntity>(cae =>
|
||||||
{
|
{
|
||||||
cae.ToTable("client_accounts");
|
cae.ToTable("client_accounts");
|
||||||
cae.HasKey(x => x.Id);
|
cae.HasKey(x => x.Id);
|
||||||
cae.HasMany(x => x.Playlists)
|
|
||||||
.WithOne()
|
|
||||||
.HasForeignKey(x => x.ChannelId);
|
|
||||||
cae.HasMany(x => x.HttpCookies)
|
cae.HasMany(x => x.HttpCookies)
|
||||||
.WithOne()
|
.WithOne()
|
||||||
.HasForeignKey(x => x.ClientId);
|
.HasForeignKey(x => x.ClientId);
|
||||||
|
@@ -14,4 +14,7 @@ public class ChannelEntity : DateTimeBase
|
|||||||
public long Subscribers { get; set; }
|
public long Subscribers { get; set; }
|
||||||
public long TotalVideos { get; set; }
|
public long TotalVideos { get; set; }
|
||||||
public long TotalViews { get; set; }
|
public long TotalViews { get; set; }
|
||||||
|
public List<MediaEntity> Media { get; set; } = [];
|
||||||
|
public List<PlaylistEntity> Playlists { get; set; } = [];
|
||||||
|
public ClientAccountEntity? ClientAccount { get; set; }
|
||||||
}
|
}
|
@@ -6,9 +6,6 @@ public class ClientAccountEntity : DateTimeBase
|
|||||||
{
|
{
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
public required string Id { get; set; }
|
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; } = [];
|
public List<HttpCookieEntity> HttpCookies { get; set; } = [];
|
||||||
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
[MaxLength(DataConstants.DbContext.DefaultDbStringSize)]
|
||||||
public string? UserAgent { get; set; }
|
public string? UserAgent { get; set; }
|
||||||
|
@@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
namespace Manager.Data.Migrations
|
namespace Manager.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(LibraryDbContext))]
|
[DbContext(typeof(LibraryDbContext))]
|
||||||
[Migration("20250831150411_initialLib")]
|
[Migration("20250902133345_InitialLibrary")]
|
||||||
partial class initialLib
|
partial class InitialLibrary
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@@ -89,8 +89,7 @@ namespace Manager.Data.Migrations
|
|||||||
b.Property<DateTime>("LastModifiedUtc")
|
b.Property<DateTime>("LastModifiedUtc")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("UserAgent")
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
.HasMaxLength(100)
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
@@ -210,6 +209,8 @@ namespace Manager.Data.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ChannelId");
|
||||||
|
|
||||||
b.ToTable("media", (string)null);
|
b.ToTable("media", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -318,6 +319,15 @@ namespace Manager.Data.Migrations
|
|||||||
.IsRequired();
|
.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 =>
|
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.HttpCookieEntity", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
|
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
|
||||||
@@ -342,6 +352,15 @@ namespace Manager.Data.Migrations
|
|||||||
.IsRequired();
|
.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 =>
|
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaFormatEntity", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
||||||
@@ -353,18 +372,25 @@ namespace Manager.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
|
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")
|
.WithMany("Playlists")
|
||||||
.HasForeignKey("ChannelId")
|
.HasForeignKey("ChannelId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.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 =>
|
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("HttpCookies");
|
b.Navigation("HttpCookies");
|
||||||
|
|
||||||
b.Navigation("Playlists");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
@@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
namespace Manager.Data.Migrations
|
namespace Manager.Data.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class initialLib : Migration
|
public partial class InitialLibrary : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
@@ -35,13 +35,19 @@ namespace Manager.Data.Migrations
|
|||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
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),
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
LastModifiedUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_client_accounts", x => x.Id);
|
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(
|
migrationBuilder.CreateTable(
|
||||||
@@ -62,6 +68,34 @@ namespace Manager.Data.Migrations
|
|||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_media", x => x.Id);
|
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(
|
migrationBuilder.CreateTable(
|
||||||
@@ -91,28 +125,6 @@ namespace Manager.Data.Migrations
|
|||||||
onDelete: ReferentialAction.Cascade);
|
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(
|
migrationBuilder.CreateTable(
|
||||||
name: "captions",
|
name: "captions",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@@ -201,6 +213,11 @@ namespace Manager.Data.Migrations
|
|||||||
table: "join_playlist_media",
|
table: "join_playlist_media",
|
||||||
column: "MediaId");
|
column: "MediaId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_media_ChannelId",
|
||||||
|
table: "media",
|
||||||
|
column: "ChannelId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_playlists_ChannelId",
|
name: "IX_playlists_ChannelId",
|
||||||
table: "playlists",
|
table: "playlists",
|
||||||
@@ -213,9 +230,6 @@ namespace Manager.Data.Migrations
|
|||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "captions");
|
name: "captions");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "channels");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "http_cookies");
|
name: "http_cookies");
|
||||||
|
|
||||||
@@ -225,6 +239,9 @@ namespace Manager.Data.Migrations
|
|||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "media_formats");
|
name: "media_formats");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "client_accounts");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "playlists");
|
name: "playlists");
|
||||||
|
|
||||||
@@ -232,7 +249,7 @@ namespace Manager.Data.Migrations
|
|||||||
name: "media");
|
name: "media");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "client_accounts");
|
name: "channels");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -86,8 +86,7 @@ namespace Manager.Data.Migrations
|
|||||||
b.Property<DateTime>("LastModifiedUtc")
|
b.Property<DateTime>("LastModifiedUtc")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("UserAgent")
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(100)
|
.HasMaxLength(100)
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
@@ -207,6 +206,8 @@ namespace Manager.Data.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ChannelId");
|
||||||
|
|
||||||
b.ToTable("media", (string)null);
|
b.ToTable("media", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -315,6 +316,15 @@ namespace Manager.Data.Migrations
|
|||||||
.IsRequired();
|
.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 =>
|
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.HttpCookieEntity", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
|
b.HasOne("Manager.Data.Entities.LibraryContext.ClientAccountEntity", null)
|
||||||
@@ -339,6 +349,15 @@ namespace Manager.Data.Migrations
|
|||||||
.IsRequired();
|
.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 =>
|
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaFormatEntity", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
b.HasOne("Manager.Data.Entities.LibraryContext.MediaEntity", null)
|
||||||
@@ -350,18 +369,25 @@ namespace Manager.Data.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.PlaylistEntity", b =>
|
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")
|
.WithMany("Playlists")
|
||||||
.HasForeignKey("ChannelId")
|
.HasForeignKey("ChannelId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.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 =>
|
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.ClientAccountEntity", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("HttpCookies");
|
b.Navigation("HttpCookies");
|
||||||
|
|
||||||
b.Navigation("Playlists");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
modelBuilder.Entity("Manager.Data.Entities.LibraryContext.MediaEntity", b =>
|
||||||
|
@@ -12,4 +12,7 @@ Update the database
|
|||||||
```shell
|
```shell
|
||||||
dotnet ef database update --project Manager.Data --startup-project Manager.App --context Manager.Data.Contexts.LibraryDbContext
|
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
|
||||||
|
```
|
||||||
|
Reference in New Issue
Block a user