Improved data model #378
This commit is contained in:
parent
a303108da2
commit
0b767fcb68
@ -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;
|
@ -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),
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,6 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ShortRoleNamePositionEnum(Enum):
|
||||
before = "Before"
|
||||
after = "After"
|
Loading…
Reference in New Issue
Block a user