From 7cb00bc6ff576e67eaecb6ead5d9468a7e4aa69b Mon Sep 17 00:00:00 2001 From: Pavel Zhur Date: Fri, 27 Sep 2024 16:57:04 +0300 Subject: [PATCH] sql to append mediae --- .../VideosDatabase.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs b/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs index 985ca023..0e5a0577 100644 --- a/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs +++ b/OneShelf.Videos/OneShelf.Videos.Database/VideosDatabase.cs @@ -38,6 +38,25 @@ public VideosDatabase(DbContextOptions options) public required DbSet AlbumConstraints { get; set; } public required DbSet UploadedAlbums { get; set; } + public async Task AppendMediae() + { + await Database.ExecuteSqlAsync(@$" + +insert into mediae (staticchatid, staticmessageid) +select sm.staticchatid, sm.id +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 +from livemediae lm +left join mediae m on m.livemediaid = lm.id and m.livechatid = lm.livetopiclivechatid +where m.id is null + +"); + } + public async Task CleanupTopics() { await Database.ExecuteSqlAsync(@$"