diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240928144400_Media15.Designer.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240928144400_Media15.Designer.cs
new file mode 100644
index 00000000..f13c1b01
--- /dev/null
+++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240928144400_Media15.Designer.cs
@@ -0,0 +1,923 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using OneShelf.Videos.Database;
+
+#nullable disable
+
+namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
+{
+ [DbContext(typeof(VideosDatabase))]
+ [Migration("20240928144400_Media15")]
+ partial class Media15
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "8.0.8")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Album", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Title")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Albums");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.AlbumConstraint", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("After")
+ .HasColumnType("datetime2");
+
+ b.Property("AlbumId")
+ .HasColumnType("int");
+
+ b.Property("Before")
+ .HasColumnType("datetime2");
+
+ b.Property("Include")
+ .HasColumnType("bit");
+
+ b.Property("IsSquare")
+ .HasColumnType("bit");
+
+ b.Property("StaticMessageSelectedType")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("TopicId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AlbumId");
+
+ b.HasIndex("TopicId");
+
+ b.ToTable("AlbumConstraints");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.InventoryItem", b =>
+ {
+ b.Property("DatabaseInventoryItemId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("DatabaseInventoryItemId"));
+
+ b.Property("BaseUrl")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ContributorInfoDisplayName")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ContributorInfoProfilePictureBaseUrl")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Description")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("FileName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Id")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("IsPhoto")
+ .HasColumnType("bit");
+
+ b.Property("IsVideo")
+ .HasColumnType("bit");
+
+ b.Property("MediaMetadataCreationTime")
+ .HasColumnType("datetime2");
+
+ b.Property("MediaMetadataHeight")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaMetadataPhotoApertureFNumber")
+ .HasColumnType("real");
+
+ b.Property("MediaMetadataPhotoCameraMake")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaMetadataPhotoCameraModel")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaMetadataPhotoExposureTime")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaMetadataPhotoFocalLength")
+ .HasColumnType("real");
+
+ b.Property("MediaMetadataPhotoIsoEquivalent")
+ .HasColumnType("int");
+
+ b.Property("MediaMetadataVideoCameraMake")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaMetadataVideoCameraModel")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaMetadataVideoFps")
+ .HasColumnType("float");
+
+ b.Property("MediaMetadataVideoStatus")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaMetadataWidth")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MimeType")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ProductUrl")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("SyncDate")
+ .HasColumnType("datetime2");
+
+ b.HasKey("DatabaseInventoryItemId");
+
+ b.ToTable("InventoryItems");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveChat", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("bigint");
+
+ b.Property("Title")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("LiveChats");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveDownloadedItem", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("FileName")
+ .IsRequired()
+ .HasColumnType("nvarchar(450)");
+
+ b.Property("LiveMediaMediaId")
+ .HasColumnType("bigint");
+
+ b.Property("ThumbnailFileName")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("FileName")
+ .IsUnique();
+
+ b.HasIndex("LiveMediaMediaId")
+ .IsUnique();
+
+ b.ToTable("LiveDownloadedItems");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveMedia", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("int");
+
+ b.Property("LiveTopicLiveChatId")
+ .HasColumnType("bigint");
+
+ b.Property("DocumentAttributeTypes")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("DocumentAttributes")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Duration")
+ .HasColumnType("float");
+
+ b.Property("FileName")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Flags")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Height")
+ .HasColumnType("int");
+
+ b.Property("IsForwarded")
+ .HasColumnType("bit");
+
+ b.Property("LiveTopicId")
+ .HasColumnType("int");
+
+ b.Property("MediaDate")
+ .HasColumnType("datetime2");
+
+ b.Property("MediaFlags")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaId")
+ .HasColumnType("bigint");
+
+ b.Property("MediaType")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MessageDate")
+ .HasColumnType("datetime2");
+
+ b.Property("MimeType")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("SelectedType")
+ .ValueGeneratedOnAddOrUpdate()
+ .HasColumnType("nvarchar(max)")
+ .HasComputedColumnSql("\r\ncase \r\nwhen type = 'Photo' then 'Photo' \r\nwhen MimeType like 'video/%' then 'Video' \r\nwhen mimetype = 'image/webp' then null \r\nwhen mimetype = 'application/x-tgsticker' then null\r\nwhen MimeType like 'image/%' then 'Photo' \r\nelse null\r\nend\r\n");
+
+ b.Property("Size")
+ .HasColumnType("bigint");
+
+ b.Property("Type")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("VideoFlags")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Width")
+ .HasColumnType("int");
+
+ b.HasKey("Id", "LiveTopicLiveChatId");
+
+ b.HasIndex("LiveTopicId", "LiveTopicLiveChatId");
+
+ b.ToTable("LiveMediae");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveTopic", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("int");
+
+ b.Property("LiveChatId")
+ .HasColumnType("bigint");
+
+ b.Property("Title")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id", "LiveChatId");
+
+ b.HasIndex("LiveChatId");
+
+ b.ToTable("LiveTopics");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Media", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("LiveChatId")
+ .HasColumnType("bigint");
+
+ b.Property("LiveMediaId")
+ .HasColumnType("int");
+
+ b.Property("StaticChatId")
+ .HasColumnType("bigint");
+
+ b.Property("StaticMessageId")
+ .HasColumnType("int");
+
+ b.Property("TopicId")
+ .HasColumnType("int");
+
+ b.Property("Type")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("LiveChatId");
+
+ b.HasIndex("TopicId");
+
+ 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("Id")
+ .HasColumnType("bigint");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("StaticChatFolderId")
+ .HasColumnType("int");
+
+ b.Property("Type")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("StaticChatFolderId")
+ .IsUnique();
+
+ b.ToTable("StaticChats");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChatFolder", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("nvarchar(450)");
+
+ b.Property("Root")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Name")
+ .IsUnique();
+
+ b.ToTable("StaticChatFolders");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticMessage", b =>
+ {
+ b.Property("StaticChatId")
+ .HasColumnType("bigint");
+
+ b.Property("Id")
+ .HasColumnType("int");
+
+ b.Property("Action")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Actor")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ActorId")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Boosts")
+ .HasColumnType("int");
+
+ b.Property("ContactInformation")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Date")
+ .HasColumnType("datetime2");
+
+ b.Property("DateUnixtime")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Duration")
+ .HasColumnType("int");
+
+ b.Property("DurationSeconds")
+ .HasColumnType("int");
+
+ b.Property("Edited")
+ .HasColumnType("datetime2");
+
+ b.Property("EditedUnixtime")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("File")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("FileName")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ForwardedFrom")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("From")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("FromId")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Height")
+ .HasColumnType("int");
+
+ b.Property("InlineBotButtons")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Inviter")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("LiveLocationPeriodSeconds")
+ .HasColumnType("int");
+
+ b.Property("LocationInformation")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaType")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Members")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MessageId")
+ .HasColumnType("int");
+
+ b.Property("MimeType")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("NewIconEmojiId")
+ .HasColumnType("bigint");
+
+ b.Property("NewTitle")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Performer")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Photo")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Poll")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ReplyToMessageId")
+ .HasColumnType("int");
+
+ b.Property("ReplyToPeerId")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("SavedFrom")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ScheduleDate")
+ .HasColumnType("int");
+
+ b.Property("SelectedType")
+ .ValueGeneratedOnAddOrUpdate()
+ .HasColumnType("nvarchar(max)")
+ .HasComputedColumnSql("case when photo is not null then 'photo' when mimetype like 'video/%' and isnull(mediatype, 'null') in ('video_file', 'null') then 'video' else null end");
+
+ b.Property("StaticTopicRootMessageIdOr0")
+ .HasColumnType("int");
+
+ b.Property("StickerEmoji")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Text")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("TextEntities")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Thumbnail")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Title")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Type")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ViaBot")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Width")
+ .HasColumnType("int");
+
+ b.HasKey("StaticChatId", "Id");
+
+ b.HasIndex("StaticChatId", "StaticTopicRootMessageIdOr0");
+
+ b.ToTable("StaticMessages");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticTopic", b =>
+ {
+ b.Property("StaticChatId")
+ .HasColumnType("bigint");
+
+ b.Property("RootMessageIdOr0")
+ .HasColumnType("int");
+
+ b.Property("OriginalTitle")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Title")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("StaticChatId", "RootMessageIdOr0");
+
+ b.ToTable("StaticTopics");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Topic", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("LiveChatId")
+ .HasColumnType("bigint");
+
+ b.Property("LiveTopicId")
+ .HasColumnType("int");
+
+ b.Property("StaticChatId")
+ .HasColumnType("bigint");
+
+ b.Property("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("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("AlbumId")
+ .HasColumnType("int");
+
+ b.Property("GoogleAlbumId")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AlbumId")
+ .IsUnique();
+
+ b.ToTable("UploadedAlbums");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.UploadedItem", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("CreatedOn")
+ .HasColumnType("datetime2");
+
+ b.Property("FileNameTimestamp")
+ .HasColumnType("datetime2");
+
+ b.Property("Json")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaId")
+ .HasColumnType("int");
+
+ b.Property("MediaItemId")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaItemIsPhoto")
+ .HasColumnType("bit");
+
+ b.Property("MediaItemIsVideo")
+ .HasColumnType("bit");
+
+ b.Property("MediaItemMetadataCreationTime")
+ .HasColumnType("datetime2");
+
+ b.Property("MediaItemMimeType")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MediaItemSyncDate")
+ .HasColumnType("datetime2");
+
+ b.Property("Status")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("StatusCode")
+ .HasColumnType("int");
+
+ b.Property("StatusMessage")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("TelegramPublishedOn")
+ .HasColumnType("datetime2");
+
+ b.HasKey("Id");
+
+ b.HasIndex("MediaId")
+ .IsUnique();
+
+ b.ToTable("UploadedItems");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.AlbumConstraint", b =>
+ {
+ b.HasOne("OneShelf.Videos.Database.Models.Album", "Album")
+ .WithMany("Constraints")
+ .HasForeignKey("AlbumId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("OneShelf.Videos.Database.Models.Topic", "Topic")
+ .WithMany("AlbumConstraints")
+ .HasForeignKey("TopicId");
+
+ b.Navigation("Album");
+
+ b.Navigation("Topic");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveMedia", b =>
+ {
+ b.HasOne("OneShelf.Videos.Database.Models.Live.LiveTopic", "LiveTopic")
+ .WithMany("LiveMediae")
+ .HasForeignKey("LiveTopicId", "LiveTopicLiveChatId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("LiveTopic");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveTopic", b =>
+ {
+ b.HasOne("OneShelf.Videos.Database.Models.Live.LiveChat", "LiveChat")
+ .WithMany("LiveTopics")
+ .HasForeignKey("LiveChatId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ 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.Topic", "Topic")
+ .WithMany("Mediae")
+ .HasForeignKey("TopicId");
+
+ 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");
+
+ b.Navigation("Topic");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChat", b =>
+ {
+ b.HasOne("OneShelf.Videos.Database.Models.Static.StaticChatFolder", "StaticChatFolder")
+ .WithOne("StaticChat")
+ .HasForeignKey("OneShelf.Videos.Database.Models.Static.StaticChat", "StaticChatFolderId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("StaticChatFolder");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticMessage", b =>
+ {
+ b.HasOne("OneShelf.Videos.Database.Models.Static.StaticChat", "StaticChat")
+ .WithMany("Messages")
+ .HasForeignKey("StaticChatId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("OneShelf.Videos.Database.Models.Static.StaticTopic", "StaticTopic")
+ .WithMany("StaticMessages")
+ .HasForeignKey("StaticChatId", "StaticTopicRootMessageIdOr0");
+
+ b.Navigation("StaticChat");
+
+ b.Navigation("StaticTopic");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticTopic", b =>
+ {
+ b.HasOne("OneShelf.Videos.Database.Models.Static.StaticChat", "StaticChat")
+ .WithMany()
+ .HasForeignKey("StaticChatId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ 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")
+ .WithOne("UploadedAlbum")
+ .HasForeignKey("OneShelf.Videos.Database.Models.UploadedAlbum", "AlbumId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Album");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.UploadedItem", b =>
+ {
+ b.HasOne("OneShelf.Videos.Database.Models.Media", "Media")
+ .WithOne("UploadedItem")
+ .HasForeignKey("OneShelf.Videos.Database.Models.UploadedItem", "MediaId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Media");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Album", b =>
+ {
+ b.Navigation("Constraints");
+
+ b.Navigation("UploadedAlbum");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveChat", b =>
+ {
+ b.Navigation("LiveTopics");
+
+ b.Navigation("Mediae");
+
+ b.Navigation("Topics");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveMedia", b =>
+ {
+ b.Navigation("Media");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveTopic", b =>
+ {
+ b.Navigation("LiveMediae");
+
+ b.Navigation("Topic");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Media", b =>
+ {
+ b.Navigation("UploadedItem");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChat", b =>
+ {
+ b.Navigation("Mediae");
+
+ b.Navigation("Messages");
+
+ b.Navigation("Topics");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChatFolder", b =>
+ {
+ 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("StaticMessages");
+
+ b.Navigation("Topic");
+ });
+
+ modelBuilder.Entity("OneShelf.Videos.Database.Models.Topic", b =>
+ {
+ b.Navigation("AlbumConstraints");
+
+ b.Navigation("Mediae");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240928144400_Media15.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240928144400_Media15.cs
new file mode 100644
index 00000000..c978b904
--- /dev/null
+++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240928144400_Media15.cs
@@ -0,0 +1,48 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations
+{
+ ///
+ public partial class Media15 : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "TopicId",
+ table: "Mediae",
+ type: "int",
+ nullable: true);
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Mediae_TopicId",
+ table: "Mediae",
+ column: "TopicId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Mediae_Topics_TopicId",
+ table: "Mediae",
+ column: "TopicId",
+ principalTable: "Topics",
+ principalColumn: "Id");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Mediae_Topics_TopicId",
+ table: "Mediae");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Mediae_TopicId",
+ table: "Mediae");
+
+ migrationBuilder.DropColumn(
+ name: "TopicId",
+ table: "Mediae");
+ }
+ }
+}
diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs
index 47d59697..7055e490 100644
--- a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs
+++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs
@@ -326,6 +326,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property("StaticMessageId")
.HasColumnType("int");
+ b.Property("TopicId")
+ .HasColumnType("int");
+
b.Property("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
@@ -334,6 +337,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("LiveChatId");
+ b.HasIndex("TopicId");
+
b.HasIndex("LiveMediaId", "LiveChatId")
.IsUnique()
.HasFilter("[LiveMediaId] IS NOT NULL AND [LiveChatId] IS NOT NULL");
@@ -733,6 +738,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.WithMany("Mediae")
.HasForeignKey("StaticChatId");
+ b.HasOne("OneShelf.Videos.Database.Models.Topic", "Topic")
+ .WithMany("Mediae")
+ .HasForeignKey("TopicId");
+
b.HasOne("OneShelf.Videos.Database.Models.Live.LiveMedia", "LiveMedia")
.WithOne("Media")
.HasForeignKey("OneShelf.Videos.Database.Models.Media", "LiveMediaId", "LiveChatId");
@@ -748,6 +757,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("StaticChat");
b.Navigation("StaticMessage");
+
+ b.Navigation("Topic");
});
modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticChat", b =>
@@ -900,6 +911,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("OneShelf.Videos.Database.Models.Topic", b =>
{
b.Navigation("AlbumConstraints");
+
+ b.Navigation("Mediae");
});
#pragma warning restore 612, 618
}
diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs
index 2b197a28..da409b9f 100644
--- a/OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs
+++ b/OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs
@@ -22,4 +22,7 @@ public class Media
public MediaType Type { get; set; }
public UploadedItem? UploadedItem { get; set; }
+
+ public int? TopicId { get; set; }
+ public Topic? Topic { get; set; }
}
\ No newline at end of file
diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/Topic.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/Topic.cs
index fde8547e..a075b1e8 100644
--- a/OneShelf.Videos/OneShelf.Videos.Database/Models/Topic.cs
+++ b/OneShelf.Videos/OneShelf.Videos.Database/Models/Topic.cs
@@ -20,4 +20,5 @@ public class Topic
public LiveTopic? LiveTopic { get; set; }
public ICollection AlbumConstraints { get; set; } = null!;
+ public ICollection Mediae { get; set; } = null!;
}
\ No newline at end of file
diff --git a/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs b/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs
index 10e63aa5..42e75beb 100644
--- a/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs
+++ b/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs
@@ -39,6 +39,23 @@ public VideosDatabase(DbContextOptions options)
public required DbSet AlbumConstraints { get; set; }
public required DbSet UploadedAlbums { get; set; }
+ public async Task UpdateMediaTopics()
+ {
+ await Database.ExecuteSqlAsync(@$"
+
+update mediae
+set topicid = t.id
+from mediae m
+left join StaticMessages sm on m.staticmessageid = sm.id and m.staticchatid = sm.StaticChatId
+left join livemediae lm on m.livemediaid = lm.id and m.livechatid = lm.livetopiclivechatid
+left join statictopics st on st.StaticChatId = sm.StaticChatId and st.RootMessageIdOr0 = sm.StaticTopicRootMessageIdOr0
+left join livetopics lt on lt.LiveChatId = lm.LiveTopicLiveChatId and lt.id = lm.LiveTopicId
+inner join topics t on (t.staticchatid = t.StaticChatId and t.StaticTopicRootMessageIdOr0 = st.RootMessageIdOr0)
+ or (t.livechatid = lt.LiveChatId and t.livetopicid = lt.Id)
+
+");
+ }
+
public async Task AppendTopics()
{
var staticTopics = await StaticTopics.Where(x => x.Topic == null).ToListAsync();
@@ -124,7 +141,7 @@ insert into statictopics (staticchatid, rootmessageidor0, originaltitle, title)
select nt.staticchatid, nt.rootmessageidor0, case when nt.title is null then nt.name else nt.name + ' / ' + nt.title end, case when nt.title is null then nt.name else nt.name + ' / ' + nt.title end
from newtopics nt
left join statictopics t on t.staticchatid = nt.staticchatid and nt.rootmessageidor0 = t.rootmessageidor0
-where t.id is null
+where t.staticchatid is null
ORDER BY nt.staticchatid, nt.rootmessageidor0
");