Skip to content

Commit

Permalink
topics added
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Sep 28, 2024
1 parent c48e1db commit 120193e
Show file tree
Hide file tree
Showing 9 changed files with 1,074 additions and 9 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
{
/// <inheritdoc />
public partial class Media11 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Topics",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
StaticChatId = table.Column<long>(type: "bigint", nullable: true),
StaticTopicRootMessageIdOr0 = table.Column<int>(type: "int", nullable: true),
LiveChatId = table.Column<long>(type: "bigint", nullable: true),
LiveTopicId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Topics", x => x.Id);
table.ForeignKey(
name: "FK_Topics_LiveChats_LiveChatId",
column: x => x.LiveChatId,
principalTable: "LiveChats",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Topics_LiveTopics_LiveTopicId_LiveChatId",
columns: x => new { x.LiveTopicId, x.LiveChatId },
principalTable: "LiveTopics",
principalColumns: new[] { "Id", "LiveChatId" });
table.ForeignKey(
name: "FK_Topics_StaticChats_StaticChatId",
column: x => x.StaticChatId,
principalTable: "StaticChats",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Topics_StaticTopics_StaticChatId_StaticTopicRootMessageIdOr0",
columns: x => new { x.StaticChatId, x.StaticTopicRootMessageIdOr0 },
principalTable: "StaticTopics",
principalColumns: new[] { "StaticChatId", "RootMessageIdOr0" });
});

migrationBuilder.CreateIndex(
name: "IX_Topics_LiveChatId",
table: "Topics",
column: "LiveChatId");

migrationBuilder.CreateIndex(
name: "IX_Topics_LiveTopicId_LiveChatId",
table: "Topics",
columns: new[] { "LiveTopicId", "LiveChatId" },
unique: true,
filter: "[LiveTopicId] IS NOT NULL AND [LiveChatId] IS NOT NULL");

migrationBuilder.CreateIndex(
name: "IX_Topics_StaticChatId_StaticTopicRootMessageIdOr0",
table: "Topics",
columns: new[] { "StaticChatId", "StaticTopicRootMessageIdOr0" },
unique: true,
filter: "[StaticChatId] IS NOT NULL AND [StaticTopicRootMessageIdOr0] IS NOT NULL");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Topics");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,41 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("StaticTopics");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.Topic", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

b.Property<long?>("LiveChatId")
.HasColumnType("bigint");

b.Property<int?>("LiveTopicId")
.HasColumnType("int");

b.Property<long?>("StaticChatId")
.HasColumnType("bigint");

b.Property<int?>("StaticTopicRootMessageIdOr0")
.HasColumnType("int");

b.HasKey("Id");

b.HasIndex("LiveChatId");

b.HasIndex("LiveTopicId", "LiveChatId")
.IsUnique()
.HasFilter("[LiveTopicId] IS NOT NULL AND [LiveChatId] IS NOT NULL");

b.HasIndex("StaticChatId", "StaticTopicRootMessageIdOr0")
.IsUnique()
.HasFilter("[StaticChatId] IS NOT NULL AND [StaticTopicRootMessageIdOr0] IS NOT NULL");

b.ToTable("Topics");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.UploadedAlbum", b =>
{
b.Property<int>("Id")
Expand Down Expand Up @@ -749,6 +784,33 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("StaticChat");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.Topic", b =>
{
b.HasOne("OneShelf.Videos.Database.Models.Live.LiveChat", "LiveChat")
.WithMany("Topics")
.HasForeignKey("LiveChatId");

b.HasOne("OneShelf.Videos.Database.Models.Static.StaticChat", "StaticChat")
.WithMany("Topics")
.HasForeignKey("StaticChatId");

b.HasOne("OneShelf.Videos.Database.Models.Live.LiveTopic", "LiveTopic")
.WithOne("Topic")
.HasForeignKey("OneShelf.Videos.Database.Models.Topic", "LiveTopicId", "LiveChatId");

b.HasOne("OneShelf.Videos.Database.Models.Static.StaticTopic", "StaticTopic")
.WithOne("Topic")
.HasForeignKey("OneShelf.Videos.Database.Models.Topic", "StaticChatId", "StaticTopicRootMessageIdOr0");

b.Navigation("LiveChat");

b.Navigation("LiveTopic");

b.Navigation("StaticChat");

b.Navigation("StaticTopic");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.UploadedAlbum", b =>
{
b.HasOne("OneShelf.Videos.Database.Models.Album", "Album")
Expand Down Expand Up @@ -783,6 +845,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("LiveTopics");

b.Navigation("Mediae");

b.Navigation("Topics");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveMedia", b =>
Expand All @@ -793,6 +857,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveTopic", b =>
{
b.Navigation("LiveMediae");

b.Navigation("Topic");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.Media", b =>
Expand All @@ -805,6 +871,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("Mediae");

b.Navigation("Messages");

b.Navigation("Topics");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChatFolder", b =>
Expand All @@ -820,6 +888,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticTopic", b =>
{
b.Navigation("StaticMessages");

b.Navigation("Topic");
});
#pragma warning restore 612, 618
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace OneShelf.Videos.Database.Models.Live;

Expand All @@ -13,4 +12,6 @@ public class LiveChat
public ICollection<LiveTopic> LiveTopics { get; set; }

public ICollection<Media> Mediae { get; set; }

public ICollection<Topic> Topics { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public class LiveTopic
public string Title { get; set; }

public ICollection<LiveMedia> LiveMediae { get; set; }

public Topic? Topic { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public class StaticChat

[JsonIgnore]
public ICollection<Media> Mediae { get; set; }

[JsonIgnore]
public ICollection<Topic> Topics { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public class StaticTopic
public required string Title { get; set; }

public ICollection<StaticMessage> StaticMessages { get; set; }

public Topic? Topic { get; set; }
}
12 changes: 4 additions & 8 deletions OneShelf.Videos/OneShelf.Videos.Database/Models/Topic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ public class Topic
public int Id { get; set; }

public long? StaticChatId { get; set; }
public int? StaticMessageId { get; set; }
public int? StaticTopicRootMessageIdOr0 { get; set; }

public StaticChat? StaticChat { get; set; }
public StaticMessage? StaticMessage { get; set; }
public StaticTopic? StaticTopic { get; set; }

public long? LiveChatId { get; set; }
public int? LiveMediaId { get; set; }
public int? LiveTopicId { get; set; }

public LiveChat? LiveChat { get; set; }
public LiveMedia? LiveMedia { get; set; }

public MediaType Type { get; set; }

public UploadedItem? UploadedItem { get; set; }
public LiveTopic? LiveTopic { get; set; }
}
15 changes: 15 additions & 0 deletions OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public VideosDatabase(DbContextOptions<VideosDatabase> options)
public required DbSet<LiveDownloadedItem> LiveDownloadedItems { get; set; }

public required DbSet<Media> Mediae { get; set; }
public required DbSet<Topic> Topics { get; set; }

public required DbSet<UploadedItem> UploadedItems { get; set; }
public required DbSet<InventoryItem> InventoryItems { get; set; }
Expand Down Expand Up @@ -238,5 +239,19 @@ when MimeType like 'image/%' then 'Photo'
.WithMany(x => x.StaticMessages)
.IsRequired(false)
.HasForeignKey(x => new { x.StaticChatId, x.StaticTopicRootMessageIdOr0 });

modelBuilder.Entity<Topic>()
.HasOne(x => x.StaticTopic)
.WithOne(x => x.Topic)
.HasPrincipalKey<StaticTopic>(x => new { x.StaticChatId, x.RootMessageIdOr0 })
.HasForeignKey<Topic>(x => new { x.StaticChatId, x.StaticTopicRootMessageIdOr0 })
.IsRequired(false);

modelBuilder.Entity<Topic>()
.HasOne(x => x.LiveTopic)
.WithOne(x => x.Topic)
.HasPrincipalKey<LiveTopic>(x => new { x.Id, x.LiveChatId })
.HasForeignKey<Topic>(x => new { x.LiveTopicId, x.LiveChatId })
.IsRequired(false);
}
}

0 comments on commit 120193e

Please sign in to comment.