diff --git a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service1.cs b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service1.cs index 332c7122..4b221d79 100644 --- a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service1.cs +++ b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service1.cs @@ -6,6 +6,7 @@ using OneShelf.Common; using OneShelf.Videos.BusinessLogic.Models; using OneShelf.Videos.Database; +using OneShelf.Videos.Database.Models; using OneShelf.Videos.Database.Models.Static; namespace OneShelf.Videos.BusinessLogic.Services; @@ -27,7 +28,7 @@ public Service1(IOptions options, VideosDatabase videosDatabase, { var messages = await _videosDatabase.Mediae .Where(x => x.StaticMessage != null) - .Where(x => x.StaticMessage!.SelectedType == StaticMessageSelectedType.Photo) + .Where(x => x.StaticMessage!.SelectedType == MediaType.Photo) .Where(x => x.StaticMessage!.Media != null) .Where(x => x.UploadedItem == null) .Include(x => x.StaticMessage) @@ -44,7 +45,7 @@ public Service1(IOptions options, VideosDatabase videosDatabase, { var messages = await _videosDatabase.Mediae .Where(x => x.StaticMessage != null) - .Where(x => x.StaticMessage!.SelectedType == StaticMessageSelectedType.Video) + .Where(x => x.StaticMessage!.SelectedType == MediaType.Video) .Where(x => x.StaticMessage!.Media != null) .Where(x => x.UploadedItem == null) .Include(x => x.StaticMessage) diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927154926_Media7.Designer.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927154926_Media7.Designer.cs new file mode 100644 index 00000000..71c82818 --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927154926_Media7.Designer.cs @@ -0,0 +1,842 @@ +// +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("20240927154926_Media7")] + partial class Media7 + { + /// + 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("StaticTopicId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AlbumId"); + + b.HasIndex("StaticTopicId"); + + 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.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("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("StaticTopicId") + .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("StaticTopicId"); + + b.ToTable("StaticMessages"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticTopic", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OriginalTitle") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("RootMessageIdOr0") + .HasColumnType("int"); + + b.Property("StaticChatId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("StaticChatId", "RootMessageIdOr0") + .IsUnique(); + + b.ToTable("StaticTopics"); + }); + + 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.Static.StaticTopic", "StaticTopic") + .WithMany("AlbumConstraints") + .HasForeignKey("StaticTopicId"); + + b.Navigation("Album"); + + b.Navigation("StaticTopic"); + }); + + 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.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") + .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("StaticTopicId"); + + 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.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"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveMedia", b => + { + b.Navigation("Media"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveTopic", b => + { + b.Navigation("LiveMediae"); + }); + + 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"); + }); + + 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("AlbumConstraints"); + + b.Navigation("StaticMessages"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927154926_Media7.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927154926_Media7.cs new file mode 100644 index 00000000..35e1d7a1 --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927154926_Media7.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations +{ + /// + public partial class Media7 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "SelectedType", + table: "LiveMediae", + type: "nvarchar(max)", + nullable: true, + computedColumnSql: "\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"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "SelectedType", + table: "LiveMediae"); + } + } +} diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155120_Media8.Designer.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155120_Media8.Designer.cs new file mode 100644 index 00000000..b20aa937 --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155120_Media8.Designer.cs @@ -0,0 +1,845 @@ +// +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("20240927155120_Media8")] + partial class Media8 + { + /// + 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("StaticTopicId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AlbumId"); + + b.HasIndex("StaticTopicId"); + + 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("Type") + .HasColumnType("nvarchar(max)"); + + 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("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("StaticTopicId") + .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("StaticTopicId"); + + b.ToTable("StaticMessages"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticTopic", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OriginalTitle") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("RootMessageIdOr0") + .HasColumnType("int"); + + b.Property("StaticChatId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("StaticChatId", "RootMessageIdOr0") + .IsUnique(); + + b.ToTable("StaticTopics"); + }); + + 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.Static.StaticTopic", "StaticTopic") + .WithMany("AlbumConstraints") + .HasForeignKey("StaticTopicId"); + + b.Navigation("Album"); + + b.Navigation("StaticTopic"); + }); + + 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.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") + .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("StaticTopicId"); + + 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.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"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveMedia", b => + { + b.Navigation("Media"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveTopic", b => + { + b.Navigation("LiveMediae"); + }); + + 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"); + }); + + 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("AlbumConstraints"); + + b.Navigation("StaticMessages"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155120_Media8.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155120_Media8.cs new file mode 100644 index 00000000..da82f48f --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155120_Media8.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations +{ + /// + public partial class Media8 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Type", + table: "Mediae", + type: "nvarchar(max)", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Type", + table: "Mediae"); + } + } +} diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155521_Media9.Designer.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155521_Media9.Designer.cs new file mode 100644 index 00000000..9fc47db4 --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155521_Media9.Designer.cs @@ -0,0 +1,846 @@ +// +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("20240927155521_Media9")] + partial class Media9 + { + /// + 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("StaticTopicId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AlbumId"); + + b.HasIndex("StaticTopicId"); + + 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("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + 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("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("StaticTopicId") + .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("StaticTopicId"); + + b.ToTable("StaticMessages"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Static.StaticTopic", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OriginalTitle") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("RootMessageIdOr0") + .HasColumnType("int"); + + b.Property("StaticChatId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("StaticChatId", "RootMessageIdOr0") + .IsUnique(); + + b.ToTable("StaticTopics"); + }); + + 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.Static.StaticTopic", "StaticTopic") + .WithMany("AlbumConstraints") + .HasForeignKey("StaticTopicId"); + + b.Navigation("Album"); + + b.Navigation("StaticTopic"); + }); + + 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.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") + .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("StaticTopicId"); + + 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.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"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveMedia", b => + { + b.Navigation("Media"); + }); + + modelBuilder.Entity("OneShelf.Videos.Database.Models.Live.LiveTopic", b => + { + b.Navigation("LiveMediae"); + }); + + 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"); + }); + + 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("AlbumConstraints"); + + b.Navigation("StaticMessages"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155521_Media9.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155521_Media9.cs new file mode 100644 index 00000000..bee7f460 --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927155521_Media9.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations +{ + /// + public partial class Media9 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Type", + table: "Mediae", + type: "nvarchar(max)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Type", + table: "Mediae", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + } + } +} diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs index f20247ba..db11a8f8 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs @@ -262,6 +262,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) 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"); @@ -321,6 +326,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("StaticMessageId") .HasColumnType("int"); + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + b.HasKey("Id"); b.HasIndex("LiveChatId"); diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/AlbumConstraint.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/AlbumConstraint.cs index 7bdf1c2d..1da2d67e 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/Models/AlbumConstraint.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/Models/AlbumConstraint.cs @@ -16,7 +16,7 @@ public class AlbumConstraint public StaticTopic? StaticTopic { get; set; } - public StaticMessageSelectedType? StaticMessageSelectedType { get; set; } + public MediaType? StaticMessageSelectedType { get; set; } public bool IsSquare { get; set; } diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/Live/LiveMedia.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/Live/LiveMedia.cs index 221f39e3..a59c824c 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/Models/Live/LiveMedia.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/Models/Live/LiveMedia.cs @@ -20,6 +20,8 @@ public class LiveMedia public Media? Media { get; set; } + public MediaType? SelectedType { get; set; } + public DateTime MessageDate { get; set; } public bool IsForwarded { get; set; } public DateTime MediaDate { get; set; } diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs index d6977b3a..2b197a28 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/Models/Media.cs @@ -19,5 +19,7 @@ public class Media public LiveChat? LiveChat { get; set; } public LiveMedia? LiveMedia { get; set; } + public MediaType Type { get; set; } + public UploadedItem? UploadedItem { get; set; } } \ No newline at end of file diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/MediaType.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/MediaType.cs new file mode 100644 index 00000000..73332815 --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Models/MediaType.cs @@ -0,0 +1,7 @@ +namespace OneShelf.Videos.Database.Models; + +public enum MediaType +{ + Photo, + Video, +} \ No newline at end of file diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/Static/StaticMessage.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/Static/StaticMessage.cs index 203db445..957270fb 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/Models/Static/StaticMessage.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/Models/Static/StaticMessage.cs @@ -20,7 +20,7 @@ public class StaticMessage public StaticTopic? StaticTopic { get; set; } [JsonIgnore] - public StaticMessageSelectedType? SelectedType { get; set; } + public MediaType? SelectedType { get; set; } [JsonIgnore] public Media? Media { get; set; } diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/Static/StaticMessageSelectedType.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/Static/StaticMessageSelectedType.cs deleted file mode 100644 index 4de4cf31..00000000 --- a/OneShelf.Videos/OneShelf.Videos.Database/Models/Static/StaticMessageSelectedType.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace OneShelf.Videos.Database.Models.Static; - -public enum StaticMessageSelectedType -{ - Photo, - Video, -} \ 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 0e5a0577..f6be509d 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs @@ -42,17 +42,17 @@ public async Task AppendMediae() { await Database.ExecuteSqlAsync(@$" -insert into mediae (staticchatid, staticmessageid) -select sm.staticchatid, sm.id +insert into mediae (staticchatid, staticmessageid, type) +select sm.staticchatid, sm.id, sm.selectedtype from StaticMessages sm left join mediae m on m.staticmessageid = sm.id and m.staticchatid = sm.StaticChatId where sm.SelectedType is not null and m.id is null -insert into mediae (livechatid, livemediaid) -select lm.livetopiclivechatid, lm.id +insert into mediae (livechatid, livemediaid, type) +select lm.livetopiclivechatid, lm.id, lm.selectedtype from livemediae lm left join mediae m on m.livemediaid = lm.id and m.livechatid = lm.livetopiclivechatid -where m.id is null +where lm.SelectedType is not null and m.id is null "); } @@ -213,5 +213,24 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasPrincipalKey(x => new { x.Id, x.LiveTopicLiveChatId }) .HasForeignKey(x => new { x.LiveMediaId, x.LiveChatId }) .IsRequired(false); + + modelBuilder.Entity() + .Property(x => x.SelectedType) + .HasConversion() + .HasComputedColumnSql( + @" +case +when type = 'Photo' then 'Photo' +when MimeType like 'video/%' then 'Video' +when mimetype = 'image/webp' then null +when mimetype = 'application/x-tgsticker' then null +when MimeType like 'image/%' then 'Photo' +else null +end +"); + + modelBuilder.Entity() + .Property(x => x.Type) + .HasConversion(); } } \ No newline at end of file