Improved data model #378
This commit is contained in:
parent
a303108da2
commit
0b767fcb68
@ -1,12 +1,13 @@
|
|||||||
CREATE TABLE IF NOT EXISTS `ShortRoleNamesHistory`
|
CREATE TABLE IF NOT EXISTS `ShortRoleNamesHistory`
|
||||||
(
|
(
|
||||||
`Id` BIGINT(20) NOT NULL,
|
`Id` BIGINT(20) NOT NULL,
|
||||||
`ShortName` VARCHAR(64) DEFAULT 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,
|
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||||
`Deleted` BOOL DEFAULT FALSE,
|
`Deleted` BOOL DEFAULT FALSE,
|
||||||
`DateFrom` DATETIME(6) NOT NULL,
|
`DateFrom` DATETIME(6) NOT NULL,
|
||||||
`DateTo` DATETIME(6) NOT NULL
|
`DateTo` DATETIME(6) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS `TR_ShortRoleNamesUpdate`;
|
DROP TRIGGER IF EXISTS `TR_ShortRoleNamesUpdate`;
|
||||||
@ -16,8 +17,10 @@ CREATE TRIGGER `TR_ShortRoleNamesUpdate`
|
|||||||
ON `ShortRoleNames`
|
ON `ShortRoleNames`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `ServerId`, `DateFrom`, `DateTo`)
|
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `Position`, `ServerId`, `DateFrom`,
|
||||||
VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6));
|
`DateTo`)
|
||||||
|
VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.Position, OLD.ServerId, OLD.LastModifiedAt,
|
||||||
|
CURRENT_TIMESTAMP(6));
|
||||||
END;
|
END;
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS `TR_ShortRoleNamesDelete`;
|
DROP TRIGGER IF EXISTS `TR_ShortRoleNamesDelete`;
|
||||||
@ -29,6 +32,6 @@ CREATE TRIGGER `TR_ShortRoleNamesDelete`
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `ServerId`, `Deleted`, `DateFrom`,
|
INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `ServerId`, `Deleted`, `DateFrom`,
|
||||||
`DateTo`)
|
`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));
|
CURRENT_TIMESTAMP(6));
|
||||||
END;
|
END;
|
@ -22,6 +22,7 @@ class ShortRoleNameMigration(MigrationABC):
|
|||||||
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
`Id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||||
`ShortName` VARCHAR(255) NOT NULL,
|
`ShortName` VARCHAR(255) NOT NULL,
|
||||||
`DiscordRoleId` BIGINT NOT NULL,
|
`DiscordRoleId` BIGINT NOT NULL,
|
||||||
|
`Position` ENUM('Before', 'After') NOT NULL,
|
||||||
`ServerId` BIGINT,
|
`ServerId` BIGINT,
|
||||||
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
|
`CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||||
`LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE 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 cpl_discord.service import DiscordBotServiceABC
|
||||||
|
|
||||||
from bot_data.model.server import Server
|
from bot_data.model.server import Server
|
||||||
|
from bot_data.model.short_role_name_position_enum import ShortRoleNamePositionEnum
|
||||||
|
|
||||||
|
|
||||||
class ShortRoleName(TableABC):
|
class ShortRoleName(TableABC):
|
||||||
@ -12,6 +13,7 @@ class ShortRoleName(TableABC):
|
|||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
discord_role_id: int,
|
discord_role_id: int,
|
||||||
|
position: ShortRoleNamePositionEnum,
|
||||||
server: Server,
|
server: Server,
|
||||||
created_at: datetime = None,
|
created_at: datetime = None,
|
||||||
modified_at: datetime = None,
|
modified_at: datetime = None,
|
||||||
@ -20,6 +22,7 @@ class ShortRoleName(TableABC):
|
|||||||
self._id = id
|
self._id = id
|
||||||
self._name = name
|
self._name = name
|
||||||
self._discord_role_id = discord_role_id
|
self._discord_role_id = discord_role_id
|
||||||
|
self._position = position
|
||||||
self._server = server
|
self._server = server
|
||||||
|
|
||||||
TableABC.__init__(self)
|
TableABC.__init__(self)
|
||||||
@ -52,6 +55,14 @@ class ShortRoleName(TableABC):
|
|||||||
guild = bot.get_guild(self._server.discord_id)
|
guild = bot.get_guild(self._server.discord_id)
|
||||||
return guild.get_role(self.role_id).name
|
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
|
@property
|
||||||
def server(self) -> Server:
|
def server(self) -> Server:
|
||||||
return 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