From 41325766f32b29f5caa34f8d8869ba6635a0a620 Mon Sep 17 00:00:00 2001 From: Ayrat Hudaygulov Date: Mon, 8 Jul 2024 11:49:25 +0100 Subject: [PATCH] fixed missed bans (#25) --- src/VahterBanBot.Tests/BanTests.fs | 3 +++ src/VahterBanBot.Tests/MessageTests.fs | 3 +++ src/migrations/V5__lost-bans.sql | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 src/migrations/V5__lost-bans.sql diff --git a/src/VahterBanBot.Tests/BanTests.fs b/src/VahterBanBot.Tests/BanTests.fs index 2e8e17e..a7b5028 100644 --- a/src/VahterBanBot.Tests/BanTests.fs +++ b/src/VahterBanBot.Tests/BanTests.fs @@ -4,6 +4,7 @@ open System.Net open VahterBanBot.Tests.ContainerTestBase open VahterBanBot.Tests.TgMessageUtils open Xunit +open Xunit.Extensions.AssemblyFixture type BanTests(fixture: VahterTestContainers) = @@ -74,3 +75,5 @@ type BanTests(fixture: VahterTestContainers) = let! msgNotBanned = fixture.MessageBanned msgUpdate.Message Assert.False msgNotBanned } + + interface IAssemblyFixture diff --git a/src/VahterBanBot.Tests/MessageTests.fs b/src/VahterBanBot.Tests/MessageTests.fs index bb8de53..de48536 100644 --- a/src/VahterBanBot.Tests/MessageTests.fs +++ b/src/VahterBanBot.Tests/MessageTests.fs @@ -8,6 +8,7 @@ open Telegram.Bot.Types.Enums open VahterBanBot.Tests.ContainerTestBase open VahterBanBot.Tests.TgMessageUtils open Xunit +open Xunit.Extensions.AssemblyFixture type MessageTests(fixture: VahterTestContainers) = @@ -36,3 +37,5 @@ type MessageTests(fixture: VahterTestContainers) = created_at = dbMsg.Value.created_at } ) } + + interface IAssemblyFixture diff --git a/src/migrations/V5__lost-bans.sql b/src/migrations/V5__lost-bans.sql new file mode 100644 index 0000000..912341b --- /dev/null +++ b/src/migrations/V5__lost-bans.sql @@ -0,0 +1,16 @@ +ALTER TABLE banned + ALTER COLUMN banned_at TYPE TIMESTAMPTZ USING banned_at::TIMESTAMPTZ, + ALTER COLUMN message_text DROP NOT NULL; + +INSERT INTO banned (message_text, banned_user_id, banned_at, banned_by, message_id, banned_in_chat_id, banned_in_chat_username) +SELECT b.ban_reason + , b.id + , b.banned_at + , vahter.id + , NULL -- don't have it + , NULL -- don't have it + , NULL -- don't have it +FROM "user" b + JOIN "user" vahter ON vahter.id = b.banned_by +WHERE b.ban_reason IS NULL -- missed such messages in the previous migration + AND b.banned_at IS NOT NULL;