|
| 1 | +using Microsoft.EntityFrameworkCore.Migrations; |
| 2 | + |
| 3 | +#nullable disable |
| 4 | + |
| 5 | +namespace Nullinside.Api.Model.Migrations |
| 6 | +{ |
| 7 | + /// <inheritdoc /> |
| 8 | + public partial class FilterOutOurBans : Migration |
| 9 | + { |
| 10 | + /// <inheritdoc /> |
| 11 | + protected override void Up(MigrationBuilder migrationBuilder) |
| 12 | + { |
| 13 | + migrationBuilder.Sql(""" |
| 14 | + ALTER VIEW nullinside.BansWithMessagesInChat AS |
| 15 | + SELECT DISTINCT(OuterC.Id), OuterC.Channel, OuterC.TwitchUsername, OuterC.Message, OuterC.`Timestamp` |
| 16 | + FROM nullinside.TwitchUserChatLogs as OuterC |
| 17 | + JOIN ( |
| 18 | + SELECT c.Id, c.Channel, c.TwitchId, c.TwitchUsername, c.Reason, c.`Timestamp` |
| 19 | + FROM nullinside.TwitchUserBannedOutsideOfBotLogs as c |
| 20 | + JOIN ( |
| 21 | + SELECT Channel, TwitchUsername, COUNT(1) AS MessageCount |
| 22 | + FROM nullinside.TwitchUserChatLogs |
| 23 | + GROUP BY Channel, TwitchUsername |
| 24 | + HAVING MessageCount <= 3 |
| 25 | + ) AS Logs ON c.Channel = Logs.Channel AND c.TwitchUsername = Logs.TwitchUsername |
| 26 | + WHERE NOT EXISTS ( |
| 27 | + SELECT 1 |
| 28 | + FROM nullinside.TwitchBan ba |
| 29 | + JOIN nullinside.Users tu on ba.ChannelId = tu.TwitchId |
| 30 | + JOIN nullinside.TwitchUser tu2 on ba.BannedUserTwitchId = tu2.TwitchId |
| 31 | + WHERE tu.TwitchUsername = c.Channel AND tu2.TwitchUsername = c.TwitchUsername |
| 32 | + ) |
| 33 | + ) AS OuterLogs ON OuterC.Channel = OuterLogs.Channel AND OuterC.TwitchUsername = OuterLogs.TwitchUsername |
| 34 | + ORDER BY Message ASC |
| 35 | + """); |
| 36 | + } |
| 37 | + |
| 38 | + /// <inheritdoc /> |
| 39 | + protected override void Down(MigrationBuilder migrationBuilder) { |
| 40 | + migrationBuilder.Sql(""" |
| 41 | + ALTER VIEW nullinside.BansWithMessagesInChat AS |
| 42 | + SELECT DISTINCT(OuterC.Id), OuterC.Channel, OuterC.TwitchUsername, OuterC.Message, OuterC.`Timestamp` |
| 43 | + FROM nullinside.TwitchUserChatLogs as OuterC |
| 44 | + JOIN ( |
| 45 | + SELECT c.Id, c.Channel, c.TwitchId, c.TwitchUsername, c.Reason, c.`Timestamp` |
| 46 | + FROM nullinside.TwitchUserBannedOutsideOfBotLogs as c |
| 47 | + JOIN ( |
| 48 | + SELECT Channel, TwitchUsername, COUNT(1) AS MessageCount |
| 49 | + FROM nullinside.TwitchUserChatLogs |
| 50 | + GROUP BY Channel, TwitchUsername |
| 51 | + HAVING MessageCount <= 3 |
| 52 | + ) AS Logs ON c.Channel = Logs.Channel AND c.TwitchUsername = Logs.TwitchUsername |
| 53 | + ) AS OuterLogs ON OuterC.Channel = OuterLogs.Channel AND OuterC.TwitchUsername = OuterLogs.TwitchUsername; |
| 54 | + """); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments