support #381

Merged
edraft merged 31 commits from support into master 2023-09-28 20:03:32 +02:00
4 changed files with 28 additions and 7 deletions
Showing only changes of commit 0b767fcb68 - Show all commits

View File

@ -1,12 +1,13 @@
CREATE TABLE IF NOT EXISTS `ShortRoleNamesHistory`
(
`Id` BIGINT(20) NOT NULL,
`Id` BIGINT(20) NOT NULL,
`ShortName` VARCHAR(64) DEFAULT NULL,
`DiscordRoleId` BIGINT(20) NOT NULL,
`DiscordRoleId` BIGINT(20) NOT NULL,
`Position` ENUM ('Before', 'After') NOT NULL,
`ServerId` BIGINT(20) DEFAULT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_ShortRoleNamesUpdate`;
@ -16,8 +17,10 @@ CREATE TRIGGER `TR_ShortRoleNamesUpdate`
ON `ShortRoleNames`
FOR EACH ROW
BEGIN
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `ServerId`, `DateFrom`, `DateTo`)
VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6));
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `Position`, `ServerId`, `DateFrom`,
`DateTo`)
VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.Position, OLD.ServerId, OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6));
END;
DROP TRIGGER IF EXISTS `TR_ShortRoleNamesDelete`;
@ -29,6 +32,6 @@ CREATE TRIGGER `TR_ShortRoleNamesDelete`
BEGIN
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `ServerId`, `Deleted`, `DateFrom`,
`DateTo`)
VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.ServerId, TRUE, OLD.LastModifiedAt,
VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.Position, OLD.ServerId, TRUE, OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6));
END;

View File

@ -22,6 +22,7 @@ class ShortRoleNameMigration(MigrationABC):
`Id` BIGINT NOT NULL AUTO_INCREMENT,
`ShortName` VARCHAR(255) NOT NULL,
`DiscordRoleId` BIGINT NOT NULL,
`Position` ENUM('Before', 'After') NOT NULL,
`ServerId` BIGINT,
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
`LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),

View File

@ -5,6 +5,7 @@ from cpl_core.dependency_injection import ServiceProviderABC
from cpl_discord.service import DiscordBotServiceABC
from bot_data.model.server import Server
from bot_data.model.short_role_name_position_enum import ShortRoleNamePositionEnum
class ShortRoleName(TableABC):
@ -12,6 +13,7 @@ class ShortRoleName(TableABC):
self,
name: str,
discord_role_id: int,
position: ShortRoleNamePositionEnum,
server: Server,
created_at: datetime = None,
modified_at: datetime = None,
@ -20,6 +22,7 @@ class ShortRoleName(TableABC):
self._id = id
self._name = name
self._discord_role_id = discord_role_id
self._position = position
self._server = server
TableABC.__init__(self)
@ -52,6 +55,14 @@ class ShortRoleName(TableABC):
guild = bot.get_guild(self._server.discord_id)
return guild.get_role(self.role_id).name
@property
def position(self) -> ShortRoleNamePositionEnum:
return self._position
@position.setter
def position(self, value: ShortRoleNamePositionEnum):
self._position = value
@property
def server(self) -> Server:
return self._server

View File

@ -0,0 +1,6 @@
from enum import Enum
class ShortRoleNamePositionEnum(Enum):
before = "Before"
after = "After"