2024-06-19 02:03:46 +12:00
using Microsoft.EntityFrameworkCore ;
using Microsoft.EntityFrameworkCore.Migrations ;
namespace EllieBot.Migrations ;
public static class MigrationQueries
{
public static void MigrateRero ( MigrationBuilder migrationBuilder )
{
2024-09-14 00:30:31 +12:00
if ( migrationBuilder . IsSqlite ( ) )
2024-06-19 02:03:46 +12:00
{
migrationBuilder . Sql (
@ "insert or ignore into reactionroles(guildid, channelid, messageid, emote, roleid, 'group', levelreq, dateadded)
select guildid , channelid , messageid , emotename , roleid , exclusive , 0 , reactionrolemessage . dateadded
from reactionrole
left join reactionrolemessage on reactionrolemessage . id = reactionrole . reactionrolemessageid
left join guildconfigs on reactionrolemessage . guildconfigid = guildconfigs . id ; ");
}
else if ( migrationBuilder . IsNpgsql ( ) )
{
2024-09-14 00:30:31 +12:00
migrationBuilder . Sql (
@"insert into reactionroles(guildid, channelid, messageid, emote, roleid, ""group" ", levelreq, dateadded)
2024-06-19 02:03:46 +12:00
select guildid , channelid , messageid , emotename , roleid , exclusive : : int , 0 , reactionrolemessage . dateadded
from reactionrole
left join reactionrolemessage on reactionrolemessage . id = reactionrole . reactionrolemessageid
left join guildconfigs on reactionrolemessage . guildconfigid = guildconfigs . id
ON CONFLICT DO NOTHING ; ");
}
else
{
throw new NotSupportedException ( "This database provider doesn't have an implementation for MigrateRero" ) ;
}
}
public static void GuildConfigCleanup ( MigrationBuilder builder )
{
builder . Sql ( $"" "
DELETE FROM "DelMsgOnCmdChannel" WHERE "GuildConfigId" is NULL ;
2024-09-14 00:30:31 +12:00
DELETE FROM "WarningPunishment" WHERE "GuildConfigId" NOT IN ( SELECT "Id" from "GuildConfigs" ) ;
DELETE FROM "StreamRoleBlacklistedUser" WHERE "StreamRoleSettingsId" is NULL ;
2024-06-19 02:03:46 +12:00
"" ");
2024-09-14 00:30:31 +12:00
}
2024-08-08 13:48:43 +12:00
2024-09-14 00:30:31 +12:00
public static void GreetSettingsCopy ( MigrationBuilder builder )
{
2024-08-08 13:48:43 +12:00
builder . Sql ( "" "
2024-09-14 00:30:31 +12:00
INSERT INTO GreetSettings ( GuildId , GreetType , MessageText , IsEnabled , ChannelId , AutoDeleteTimer )
SELECT GuildId , 0 , ChannelGreetMessageText , SendChannelGreetMessage , GreetMessageChannelId , AutoDeleteGreetMessagesTimer
FROM GuildConfigs
WHERE SendChannelGreetMessage = TRUE ;
INSERT INTO GreetSettings ( GuildId , GreetType , MessageText , IsEnabled , ChannelId , AutoDeleteTimer )
SELECT GuildId , 1 , DmGreetMessageText , SendDmGreetMessage , GreetMessageChannelId , 0
FROM GuildConfigs
WHERE SendDmGreetMessage = TRUE ;
INSERT INTO GreetSettings ( GuildId , GreetType , MessageText , IsEnabled , ChannelId , AutoDeleteTimer )
SELECT GuildId , 2 , ChannelByeMessageText , SendChannelByeMessage , ByeMessageChannelId , AutoDeleteByeMessagesTimer
FROM GuildConfigs
WHERE SendChannelByeMessage = TRUE ;
INSERT INTO GreetSettings ( GuildId , GreetType , MessageText , IsEnabled , ChannelId , AutoDeleteTimer )
SELECT GuildId , 3 , BoostMessage , SendBoostMessage , BoostMessageChannelId , BoostMessageDeleteAfter
FROM GuildConfigs
WHERE SendBoostMessage = TRUE ;
2024-08-08 13:48:43 +12:00
"" ");
2024-06-19 02:03:46 +12:00
}
}