Skip to content

Commit

Permalink
fixed missed bans (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer authored Jul 8, 2024
1 parent 9a83a4d commit 4132576
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/VahterBanBot.Tests/BanTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =

Expand Down Expand Up @@ -74,3 +75,5 @@ type BanTests(fixture: VahterTestContainers) =
let! msgNotBanned = fixture.MessageBanned msgUpdate.Message
Assert.False msgNotBanned
}

interface IAssemblyFixture<VahterTestContainers>
3 changes: 3 additions & 0 deletions src/VahterBanBot.Tests/MessageTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =

Expand Down Expand Up @@ -36,3 +37,5 @@ type MessageTests(fixture: VahterTestContainers) =
created_at = dbMsg.Value.created_at }
)
}

interface IAssemblyFixture<VahterTestContainers>
16 changes: 16 additions & 0 deletions src/migrations/V5__lost-bans.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 4132576

Please sign in to comment.