Skip to content

Commit

Permalink
media table added
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Sep 27, 2024
1 parent 21e57a5 commit 84567cc
Show file tree
Hide file tree
Showing 9 changed files with 1,015 additions and 13 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 Media2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Mediae",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
StaticChatId = table.Column<long>(type: "bigint", nullable: true),
StaticMessageId = table.Column<int>(type: "int", nullable: true),
LiveChatId = table.Column<long>(type: "bigint", nullable: true),
LiveMediaId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Mediae", x => x.Id);
table.ForeignKey(
name: "FK_Mediae_LiveChats_LiveChatId",
column: x => x.LiveChatId,
principalTable: "LiveChats",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Mediae_LiveMediae_LiveMediaId_LiveChatId",
columns: x => new { x.LiveMediaId, x.LiveChatId },
principalTable: "LiveMediae",
principalColumns: new[] { "Id", "LiveTopicLiveChatId" });
table.ForeignKey(
name: "FK_Mediae_StaticChats_StaticChatId",
column: x => x.StaticChatId,
principalTable: "StaticChats",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Mediae_StaticMessages_StaticChatId_StaticMessageId",
columns: x => new { x.StaticChatId, x.StaticMessageId },
principalTable: "StaticMessages",
principalColumns: new[] { "StaticChatId", "Id" });
});

migrationBuilder.CreateIndex(
name: "IX_Mediae_LiveChatId",
table: "Mediae",
column: "LiveChatId");

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

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

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

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

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

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

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

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

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

b.HasKey("Id");

b.HasIndex("LiveChatId");

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

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

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

modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChat", b =>
{
b.Property<long>("Id")
Expand Down Expand Up @@ -653,6 +688,33 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("LiveChat");
});

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

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

b.HasOne("OneShelf.Videos.Database.Models.Live.LiveMedia", "LiveMedia")
.WithOne("Media")
.HasForeignKey("OneShelf.Videos.Database.Models.Media", "LiveMediaId", "LiveChatId");

b.HasOne("OneShelf.Videos.Database.Models.Static.StaticMessage", "StaticMessage")
.WithOne("Media")
.HasForeignKey("OneShelf.Videos.Database.Models.Media", "StaticChatId", "StaticMessageId");

b.Navigation("LiveChat");

b.Navigation("LiveMedia");

b.Navigation("StaticChat");

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

modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChat", b =>
{
b.HasOne("OneShelf.Videos.Database.Models.Static.StaticChatFolder", "StaticChatFolder")
Expand Down Expand Up @@ -713,6 +775,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveChat", b =>
{
b.Navigation("LiveTopics");

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

modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveMedia", b =>
{
b.Navigation("Media");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveTopic", b =>
Expand All @@ -722,6 +791,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChat", b =>
{
b.Navigation("Mediae");

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

Expand All @@ -730,6 +801,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("StaticChat");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticMessage", b =>
{
b.Navigation("Media");
});

modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticTopic", b =>
{
b.Navigation("AlbumConstraints");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace OneShelf.Videos.Database.Models.Live;

Expand All @@ -10,4 +11,6 @@ public class LiveChat
public string Title { get; set; }

public ICollection<LiveTopic> LiveTopics { get; set; }

public ICollection<Media> Mediae { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;

namespace OneShelf.Videos.Database.Models.Live;
Expand All @@ -17,6 +18,8 @@ public class LiveMedia

public LiveMediaType Type { get; set; }

public Media? Media { get; set; }

public DateTime MessageDate { get; set; }
public bool IsForwarded { get; set; }
public DateTime MediaDate { get; set; }
Expand Down
25 changes: 16 additions & 9 deletions OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
using OneShelf.Videos.Database.Models.Static;
using OneShelf.Videos.Database.Models.Live;
using OneShelf.Videos.Database.Models.Static;

namespace OneShelf.Videos.Database.Models;

//public class Media
//{
// public int Id { get; set; }
public class Media
{
public int Id { get; set; }

// public long? StaticChatId { get; init; }
// public int? StaticMessageId { get; init; }
public long? StaticChatId { get; set; }
public int? StaticMessageId { get; set; }

// public StaticChat? StaticChat { get; init; }
// public StaticMessage? StaticMessage { get; init; }
//}
public StaticChat? StaticChat { get; set; }
public StaticMessage? StaticMessage { get; set; }

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

public LiveChat? LiveChat { get; set; }
public LiveMedia? LiveMedia { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public class StaticChat
[JsonIgnore]
public StaticChatFolder StaticChatFolder { get; set; } = null!;

//[JsonIgnore]
//public ICollection<Media> Mediae { get; set; }
[JsonIgnore]
public ICollection<Media> Mediae { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class StaticMessage
[JsonIgnore]
public StaticMessageSelectedType? SelectedType { get; set; }

//[JsonIgnore]
//public Media? Media { get; set; }
[JsonIgnore]
public Media? Media { get; set; }

public required int Id { get; set; }
public int? MessageId { get; set; }
Expand Down
16 changes: 16 additions & 0 deletions OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public VideosDatabase(DbContextOptions<VideosDatabase> options)
public required DbSet<LiveMedia> LiveMediae { get; set; }
public required DbSet<LiveDownloadedItem> LiveDownloadedItems { get; set; }

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

public required DbSet<UploadedItem> UploadedItems { get; set; }
public required DbSet<InventoryItem> InventoryItems { get; set; }
public required DbSet<Album> Albums { get; set; }
Expand Down Expand Up @@ -178,5 +180,19 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<LiveMedia>()
.Property(x => x.Type)
.HasConversion<string>();

modelBuilder.Entity<Media>()
.HasOne(x => x.StaticMessage)
.WithOne(x => x.Media)
.HasPrincipalKey<StaticMessage>(x => new { x.StaticChatId, x.Id })
.HasForeignKey<Media>(x => new { x.StaticChatId, x.StaticMessageId })
.IsRequired(false);

modelBuilder.Entity<Media>()
.HasOne(x => x.LiveMedia)
.WithOne(x => x.Media)
.HasPrincipalKey<LiveMedia>(x => new { x.Id, x.LiveTopicLiveChatId })
.HasForeignKey<Media>(x => new { x.LiveMediaId, x.LiveChatId })
.IsRequired(false);
}
}

0 comments on commit 84567cc

Please sign in to comment.