From 7d0d7781c53058d8020e80448e8594b1b52ed77b Mon Sep 17 00:00:00 2001 From: Pavel Zhur Date: Fri, 27 Sep 2024 18:25:52 +0300 Subject: [PATCH] uploaded item old foreign keys dropped --- .../Services/ExifService.cs | 12 +- .../Services/Service1.cs | 56 +- .../Services/Service2.cs | 39 +- .../Services/VideosDatabaseOperations.cs | 5 +- .../20240927152527_Media6.Designer.cs | 837 ++++++++++++++++++ .../Migrations/20240927152527_Media6.cs | 40 + .../Migrations/VideosDatabaseModelSnapshot.cs | 6 - .../Models/UploadedItem.cs | 3 - 8 files changed, 935 insertions(+), 63 deletions(-) create mode 100644 OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927152527_Media6.Designer.cs create mode 100644 OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927152527_Media6.cs diff --git a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/ExifService.cs b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/ExifService.cs index 0bdd3ab5..1e9c39eb 100644 --- a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/ExifService.cs +++ b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/ExifService.cs @@ -1,22 +1,16 @@ -using System.Globalization; -using ExifLibrary; -using OneShelf.Common; +using ExifLibrary; namespace OneShelf.Videos.BusinessLogic.Services; public class ExifService { - public async Task SetExifTimestamp(string path, string tempFileName) + public async Task SetExifTimestamp(string path, string tempFileName, DateTime timestamp) { var image = await ImageFile.FromFileAsync(path); if (image.Errors.Any()) throw new($"Some image errors, {path}."); if (image.Properties.Contains(ExifTag.DateTime)) throw new($"The image contains a datetime, {path}."); - var dateTime = DateTime.ParseExact(Path.GetFileNameWithoutExtension(path).SelectSingle(x => x.Substring(x.IndexOf('@') + 1)), "dd-MM-yyyy_HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); - - image.Properties.Set(ExifTag.DateTime, dateTime); + image.Properties.Set(ExifTag.DateTime, timestamp); await image.SaveAsync(tempFileName); - - return dateTime; } } \ No newline at end of file diff --git a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service1.cs b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service1.cs index 2d280ca9..77a93b33 100644 --- a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service1.cs +++ b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service1.cs @@ -23,31 +23,37 @@ public Service1(IOptions options, VideosDatabase videosDatabase, _logger = logger; } - public async Task> GetExport1() + public async Task> GetExport1() { - var messages = await _videosDatabase.StaticMessages - .Where(x => x.SelectedType == StaticMessageSelectedType.Photo) - .Include(x => x.StaticChat) + var messages = await _videosDatabase.Mediae + .Where(x => x.StaticMessage != null) + .Where(x => x.StaticMessage!.SelectedType == StaticMessageSelectedType.Photo) + .Where(x => x.StaticMessage!.Media != null) + .Where(x => x.UploadedItem == null) + .Include(x => x.StaticMessage) + .ThenInclude(x => x.StaticChat) .ThenInclude(x => x.StaticChatFolder) - .Where(x => !_videosDatabase.UploadedItems.Any(y => y.StaticChatId == x.StaticChatId && y.StaticMessageId == x.Id)) .ToListAsync(); return messages - .Select(x => (x.StaticChat.Id, x.Id, Path.Combine(x.StaticChat.StaticChatFolder.Root, x.Photo!), x.Date)) + .Select(x => (x.Id, Path.Combine(x.StaticMessage!.StaticChat.StaticChatFolder.Root, x.StaticMessage.Photo!), x.StaticMessage.Date)) .ToList(); } - public async Task> GetExport2() + public async Task> GetExport2() { - var messages = await _videosDatabase.StaticMessages - .Where(x => x.SelectedType == StaticMessageSelectedType.Video) - .Include(x => x.StaticChat) + var messages = await _videosDatabase.Mediae + .Where(x => x.StaticMessage != null) + .Where(x => x.StaticMessage!.SelectedType == StaticMessageSelectedType.Video) + .Where(x => x.StaticMessage!.Media != null) + .Where(x => x.UploadedItem == null) + .Include(x => x.StaticMessage) + .ThenInclude(x => x.StaticChat) .ThenInclude(x => x.StaticChatFolder) - .Where(x => !_videosDatabase.UploadedItems.Any(y => y.StaticChatId == x.StaticChatId && y.StaticMessageId == x.Id)) .ToListAsync(); return messages - .Select(x => (x.StaticChat.Id, x.Id, Path.Combine(x.StaticChat.StaticChatFolder.Root, x.File!), x.Date)) + .Select(x => (x.Id, Path.Combine(x.StaticMessage!.StaticChat.StaticChatFolder.Root, x.StaticMessage.File!), x.StaticMessage.Date)) .ToList(); } @@ -93,7 +99,7 @@ public async Task SaveMessages() _logger.LogInformation("Saved."); } - public async Task items)>> GetAlbums() + public async Task items)>> GetAlbums() { var albums = await _videosDatabase.Albums .Where(x => x.UploadedAlbum == null) @@ -101,24 +107,24 @@ public async Task SaveMessages() .ThenInclude(x => x.StaticTopic) .ToListAsync(); - var messages = (await _videosDatabase.StaticMessages - .Where(x => x.SelectedType.HasValue && x.StaticTopicId.HasValue) + var messages = (await _videosDatabase.Mediae + .Where(x => x.StaticMessage != null) + .Where(x => x.StaticMessage!.SelectedType.HasValue && x.StaticMessage.StaticTopicId.HasValue) .Select(m => new { - TopicId = m.StaticTopicId, - ChatId = m.StaticChatId, - m.Width, - m.Height, - m.Date, + TopicId = m.StaticMessage!.StaticTopicId, + m.StaticMessage.Width, + m.StaticMessage.Height, + m.StaticMessage.Date, + m.StaticMessage.SelectedType, m.Id, - m.SelectedType, }) .ToListAsync()) .ToLookup(x => x.TopicId!.Value); var uploadedItems = await _videosDatabase.UploadedItems .Where(i => _videosDatabase.InventoryItems.Any(j => j.Id == i.MediaItemId && (j.IsPhoto || j.MediaMetadataVideoStatus == "READY"))) - .ToDictionaryAsync(x => new { ChatId = x.StaticChatId, MessageId = x.StaticMessageId, }, x => x.MediaItemId); + .ToDictionaryAsync(x => x.MediaId, x => x.MediaItemId); return albums .Select(a => (a.Id, a.Title, @@ -132,9 +138,11 @@ public async Task SaveMessages() if (c.Before.HasValue && m.Date > c.Before) return false; return true; })) - .Select(x => new { x.ChatId, MessageId = x.Id }) + .Select(x => x.Id) .Distinct() - .Select(x => (uploadedItems.GetValueOrDefault(x), x.ChatId, x.MessageId)) + .Select(x => (mediaItemId: uploadedItems.GetValueOrDefault(x), x)) + .Where(x => x.mediaItemId != null) + .Select(x => (x.mediaItemId!, x.x)) .ToList())) .ToList(); } diff --git a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service2.cs b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service2.cs index 18312819..981fcf3c 100644 --- a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service2.cs +++ b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/Service2.cs @@ -4,6 +4,7 @@ using OneShelf.Common; using OneShelf.Videos.Database; using OneShelf.Videos.Database.Models; +using System.Globalization; namespace OneShelf.Videos.BusinessLogic.Services; @@ -68,15 +69,15 @@ public async Task SaveInventory() _logger.LogInformation("Saved."); } - public async Task UploadPhotos(List<(long chatId, int messageId, string path, DateTime publishedOn)> items) + public async Task UploadPhotos(List<(int mediaId, string path, DateTime publishedOn)> items) { await _extendedGooglePhotosService.LoginAsync(); - var itemsByKey = items.ToDictionary(x => (x.chatId, x.messageId)); - var fileNameTimestamps = new Dictionary<(long chatId, int messageId), DateTime>(); + var itemsByKey = items.ToDictionary(x => x.mediaId); + var fileNameTimestamps = new Dictionary(); var result = await _extendedGooglePhotosService.UploadMultiple( items - .Select(x => ((x.chatId, x.messageId), x.path, (string?)null)) + .Select(x => (x.mediaId, x.path, (string?)null)) .ToList(), newItems => AddToDatabase(itemsByKey, newItems, fileNameTimestamps), async (x, i) => @@ -88,11 +89,13 @@ public async Task UploadPhotos(List<(long chatId, int messageId, string path, Da } Directory.CreateDirectory(tempDirectory); - var tempFileName = Path.Combine(Path.GetTempPath(), i.ToString(), Path.GetFileName(itemsByKey[x].path)); - var timestampFromFile = await _exifService.SetExifTimestamp(itemsByKey[x].path, tempFileName); + var fileName = itemsByKey[x].path; + var tempFileName = Path.Combine(Path.GetTempPath(), i.ToString(), Path.GetFileName(fileName)); + var exifTimestamp = DateTime.ParseExact(Path.GetFileNameWithoutExtension(fileName).SelectSingle(x => x.Substring(x.IndexOf('@') + 1)), "dd-MM-yyyy_HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); + await _exifService.SetExifTimestamp(fileName, tempFileName, exifTimestamp); lock (fileNameTimestamps) { - fileNameTimestamps[x] = timestampFromFile; + fileNameTimestamps[x] = exifTimestamp; } return tempFileName; @@ -102,19 +105,19 @@ public async Task UploadPhotos(List<(long chatId, int messageId, string path, Da Console.WriteLine($"started: {items.Count}, finished: {result.Count}"); } - public async Task UploadVideos(List<(long chatId, int messageId, string path, DateTime publishedOn)> items) + public async Task UploadVideos(List<(int mediaId, string path, DateTime publishedOn)> items) { await _extendedGooglePhotosService.LoginAsync(); - var added = (await _videosDatabase.UploadedItems.Select(x => new { ChatId = x.StaticChatId, MessageId = x.StaticMessageId }).ToListAsync()).ToHashSet(); + var added = (await _videosDatabase.UploadedItems.Select(x => x.MediaId).ToListAsync()).ToHashSet(); Console.WriteLine($"initial items: {items.Count}"); - items = items.Where(x => !added.Contains(new { ChatId = x.chatId, MessageId = x.messageId })).ToList(); + items = items.Where(x => !added.Contains(x.mediaId)).ToList(); Console.WriteLine($"remaining items: {items.Count}"); - var itemsByKey = items.ToDictionary(x => (x.chatId, x.messageId)); + var itemsByKey = items.ToDictionary(x => x.mediaId); var result = await _extendedGooglePhotosService.UploadMultiple( items - .Select(x => ((x.chatId, x.messageId), x.path, + .Select(x => (x.mediaId, x.path, //$"chatId = {x.chatId}, messageId = {x.messageId}, published on = {x.publishedOn}, filename = {Path.GetFileName(x.path)}" (string?)null)) .ToList(), @@ -126,22 +129,22 @@ public async Task UploadVideos(List<(long chatId, int messageId, string path, Da } private async Task AddToDatabase( - Dictionary<(long chatId, int messageId), (long chatId, int messageId, string path, DateTime publishedOn)> items, - Dictionary<(long chatId, int messageId), NewMediaItemResult> newItems, - Dictionary<(long chatId, int messageId), DateTime>? fileNameTimestamps = null) + Dictionary items, + Dictionary newItems, + Dictionary? fileNameTimestamps = null) { - _videosDatabaseOperations.AddItems(newItems.Select(i => items[i.Key].SelectSingle(x => (x.chatId, x.messageId, x.path, x.publishedOn, result: i.Value, fileNameTimestamp: fileNameTimestamps?[i.Key])))); + _videosDatabaseOperations.AddItems(newItems.Select(i => items[i.Key].SelectSingle(x => (x.mediaId, x.path, x.publishedOn, result: i.Value, fileNameTimestamp: fileNameTimestamps?[i.Key])))); await _videosDatabase.SaveChangesAsync(); } - public async Task CreateAlbums(List<(int albumId, string title, List<(string? mediaItemId, long chatId, int messageId)> items)> albums) + public async Task CreateAlbums(List<(int albumId, string title, List<(string mediaItemId, int mediaId)> items)> albums) { await _extendedGooglePhotosService.LoginAsync(); foreach (var (albumId, title, items) in albums) { _logger.LogInformation("{title} uploading...", title); var googleAlbum = await _extendedGooglePhotosService.CreateAlbumAsync(title); - await _extendedGooglePhotosService.AddMediaItemsToAlbumWithRetryAsync(googleAlbum!.id, items.Where(x => x.mediaItemId != null).Select(x => x.mediaItemId!).ToList()); + await _extendedGooglePhotosService.AddMediaItemsToAlbumWithRetryAsync(googleAlbum!.id, items.Select(x => x.mediaItemId).ToList()); _videosDatabase.UploadedAlbums.Add(new() { diff --git a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/VideosDatabaseOperations.cs b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/VideosDatabaseOperations.cs index 94e2a575..7b884266 100644 --- a/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/VideosDatabaseOperations.cs +++ b/OneShelf.Videos/OneShelf.Videos.BusinessLogic/Services/VideosDatabaseOperations.cs @@ -7,13 +7,12 @@ namespace OneShelf.Videos.BusinessLogic.Services; public class VideosDatabaseOperations(VideosDatabase videosDatabase) { - public void AddItems(IEnumerable<(long chatId, int messageId, string path, DateTime publishedOn, NewMediaItemResult result, DateTime? fileNameTimestamp)> items) + public void AddItems(IEnumerable<(int mediaId, string path, DateTime publishedOn, NewMediaItemResult result, DateTime? fileNameTimestamp)> items) { videosDatabase.UploadedItems.AddRange(items.Select(i => new UploadedItem { CreatedOn = DateTime.Now, - StaticChatId = i.chatId, - StaticMessageId = i.messageId, + MediaId = i.mediaId, TelegramPublishedOn = i.publishedOn, Status = i.result.status.status, StatusCode = i.result.status.code, diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927152527_Media6.Designer.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927152527_Media6.Designer.cs new file mode 100644 index 00000000..a35d5672 --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927152527_Media6.Designer.cs @@ -0,0 +1,837 @@ +// +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("20240927152527_Media6")] + partial class Media6 + { + /// + 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("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/20240927152527_Media6.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927152527_Media6.cs new file mode 100644 index 00000000..76209b0b --- /dev/null +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/20240927152527_Media6.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneShelf.Videos.Database.Migrations.VideosDatabaseMigrations +{ + /// + public partial class Media6 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "StaticChatId", + table: "UploadedItems"); + + migrationBuilder.DropColumn( + name: "StaticMessageId", + table: "UploadedItems"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "StaticChatId", + table: "UploadedItems", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AddColumn( + name: "StaticMessageId", + table: "UploadedItems", + type: "int", + nullable: false, + defaultValue: 0); + } + } +} diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs index b0dca0f9..f20247ba 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/Migrations/VideosDatabaseModelSnapshot.cs @@ -629,12 +629,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("MediaItemSyncDate") .HasColumnType("datetime2"); - b.Property("StaticChatId") - .HasColumnType("bigint"); - - b.Property("StaticMessageId") - .HasColumnType("int"); - b.Property("Status") .HasColumnType("nvarchar(max)"); diff --git a/OneShelf.Videos/OneShelf.Videos.Database/Models/UploadedItem.cs b/OneShelf.Videos/OneShelf.Videos.Database/Models/UploadedItem.cs index d333f2f6..d73ee644 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/Models/UploadedItem.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/Models/UploadedItem.cs @@ -5,9 +5,6 @@ public class UploadedItem public int Id { get; set; } public required DateTime CreatedOn { get; init; } - public required long StaticChatId { get; init; } - public required int StaticMessageId { get; init; } - public int MediaId { get; init; } public Media Media { get; init; } = null!;