Als Nutzer möchte ich Datenänderungen nach verfolgen können #246 #248

Merged
Jonas merged 17 commits from #246 into 1.0.0 2023-03-14 18:31:37 +01:00
19 changed files with 447 additions and 186 deletions
Showing only changes of commit c3ef7a746f - Show all commits

View File

@ -14,127 +14,6 @@ class DBHistoryMigration(MigrationABC):
self._db = db
self._cursor = db.cursor
def _servers(self):
self._cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS `ServersHistory`
(
`ServerId` BIGINT(20) NOT NULL,
`DiscordServerId` BIGINT(20) NOT NULL,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
def _user_game_idents(self):
self._cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS `UserGameIdentsHistory`
(
`Id` BIGINT(20) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`GameServerId` BIGINT(20) NOT NULL,
`Ident` VARCHAR(255) NOT NULL,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
def _user_joined_game_server(self):
self._cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS `UserJoinedGameServerHistory`
(
`Id` BIGINT(20) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`GameServerId` BIGINT(20) NOT NULL,
`JoinedOn` DATETIME(6) NOT NULL,
`LeavedOn` DATETIME(6) DEFAULT NULL,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
def _user_joined_server(self):
self._cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS `UserJoinedServersHistory`
(
`JoinId` BIGINT(20) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`JoinedOn` DATETIME(6) NOT NULL,
`LeavedOn` DATETIME(6) DEFAULT NULL,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
def _user_joined_voice_channel(self):
self._cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS `UserJoinedVoiceChannelHistory`
(
`JoinId` BIGINT(20) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`DiscordChannelId` BIGINT(20) NOT NULL,
`JoinedOn` DATETIME(6) NOT NULL,
`LeavedOn` DATETIME(6) DEFAULT NULL,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
def _user_message_count_per_hour(self):
self._cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS `UserMessageCountPerHourHistory`
(
`Id` BIGINT(20) NOT NULL,
`Date` DATETIME(6) NOT NULL,
`Hour` BIGINT(20) DEFAULT NULL,
`XPCount` BIGINT(20) DEFAULT NULL,
`UserId` BIGINT(20) DEFAULT NULL,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
def _users(self):
self._cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS `UsersHistory`
(
`UserId` BIGINT(20) NOT NULL,
`DiscordId` BIGINT(20) NOT NULL,
`XP` BIGINT(20) NOT NULL DEFAULT 0,
`ServerId` BIGINT(20) DEFAULT NULL,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
def _user_warnings(self):
self._cursor.execute(
f"""
CREATE TABLE IF NOT EXISTS `UserWarningsHistory`
(
`Id` BIGINT(20) NOT NULL,
`Description` VARCHAR(255) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`Author` BIGINT(20) DEFAULT NULL,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
"""
)
def upgrade(self):
self._logger.debug(__name__, "Running upgrade")
@ -167,6 +46,34 @@ class DBHistoryMigration(MigrationABC):
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/levels.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/servers.sql").read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_game_idents.sql").read()
)
self._cursor.execute(
open(
f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_joined_game_servers.sql"
).read()
)
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_joined_servers.sql").read()
)
self._cursor.execute(
open(
f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_joined_voice_channel.sql"
).read()
)
self._cursor.execute(
open(
f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_message_count_per_hour.sql"
).read()
)
self._cursor.execute(open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/users.sql").read())
self._cursor.execute(
open(f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts/user_warnings.sql").read()
)
def downgrade(self):
self._cursor.execute("DROP TABLE `ApiKeysHistory`;")

View File

@ -0,0 +1,47 @@
ALTER TABLE `Servers`
MODIFY `LastModifiedAt` DATETIME(6) NULL ON UPDATE CURRENT_TIMESTAMP(6);
ALTER TABLE `Servers`
ALTER COLUMN `CreatedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
ALTER TABLE `Servers`
ALTER COLUMN `LastModifiedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
CREATE TABLE IF NOT EXISTS `ServersHistory`
(
`ServerId` BIGINT(20) NOT NULL,
`DiscordServerId` BIGINT(20) NOT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_ServersUpdate`;
CREATE TRIGGER `TR_ServersUpdate`
AFTER UPDATE
ON `Servers`
FOR EACH ROW
BEGIN
INSERT INTO `ServersHistory` (
`ServerId`, `DiscordServerId`, `DateFrom`, `DateTo`
)
VALUES (
OLD.ServerId, OLD.DiscordServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;
DROP TRIGGER IF EXISTS `TR_ServersDelete`;
CREATE TRIGGER `TR_ServersDelete`
AFTER DELETE
ON `Servers`
FOR EACH ROW
BEGIN
INSERT INTO `ServersHistory` (
`ServerId`, `DiscordServerId`, `Deleted`, `DateFrom`, `DateTo`
)
VALUES (
OLD.ServerId, OLD.DiscordServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;

View File

@ -0,0 +1,49 @@
ALTER TABLE `UserGameIdents`
MODIFY `LastModifiedAt` DATETIME(6) NULL ON UPDATE CURRENT_TIMESTAMP(6);
ALTER TABLE `UserGameIdents`
ALTER COLUMN `CreatedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
ALTER TABLE `UserGameIdents`
ALTER COLUMN `LastModifiedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
CREATE TABLE IF NOT EXISTS `UserGameIdentsHistory`
(
`Id` BIGINT(20) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`GameServerId` BIGINT(20) NOT NULL,
`Ident` VARCHAR(255) NOT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_UserGameIdentsUpdate`;
CREATE TRIGGER `TR_UserGameIdentsUpdate`
AFTER UPDATE
ON `UserGameIdents`
FOR EACH ROW
BEGIN
INSERT INTO `UserGameIdentsHistory` (
`Id`, `UserId`, `GameServerId`, `Ident`, `DateFrom`, `DateTo`
)
VALUES (
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.Ident, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;
DROP TRIGGER IF EXISTS `TR_UserGameIdentsDelete`;
CREATE TRIGGER `TR_UserGameIdentsDelete`
AFTER DELETE
ON `UserGameIdents`
FOR EACH ROW
BEGIN
INSERT INTO `UserGameIdentsHistory` (
`Id`, `UserId`, `GameServerId`, `Ident`, `Deleted`, `DateFrom`, `DateTo`
)
VALUES (
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.Ident, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;

View File

@ -0,0 +1,50 @@
ALTER TABLE `UserJoinedGameServer`
MODIFY `LastModifiedAt` DATETIME(6) NULL ON UPDATE CURRENT_TIMESTAMP(6);
ALTER TABLE `UserJoinedGameServer`
ALTER COLUMN `CreatedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
ALTER TABLE `UserJoinedGameServer`
ALTER COLUMN `LastModifiedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
CREATE TABLE IF NOT EXISTS `UserJoinedGameServerHistory`
(
`Id` BIGINT(20) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`GameServerId` BIGINT(20) NOT NULL,
`JoinedOn` DATETIME(6) NOT NULL,
`LeavedOn` DATETIME(6) DEFAULT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_UserJoinedGameServerUpdate`;
CREATE TRIGGER `TR_UserJoinedGameServerUpdate`
AFTER UPDATE
ON `UserJoinedGameServer`
FOR EACH ROW
BEGIN
INSERT INTO `UserJoinedGameServerHistory` (
`Id`, `UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
)
VALUES (
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;
DROP TRIGGER IF EXISTS `TR_UserJoinedGameServerDelete`;
CREATE TRIGGER `TR_UserJoinedGameServerDelete`
AFTER DELETE
ON `UserJoinedGameServer`
FOR EACH ROW
BEGIN
INSERT INTO `UserJoinedGameServerHistory` (
`Id`, `UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
)
VALUES (
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;

View File

@ -0,0 +1,49 @@
ALTER TABLE `UserJoinedServers`
MODIFY `LastModifiedAt` DATETIME(6) NULL ON UPDATE CURRENT_TIMESTAMP(6);
ALTER TABLE `UserJoinedServers`
ALTER COLUMN `CreatedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
ALTER TABLE `UserJoinedServers`
ALTER COLUMN `LastModifiedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
CREATE TABLE IF NOT EXISTS `UserJoinedServersHistory`
(
`JoinId` BIGINT(20) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`JoinedOn` DATETIME(6) NOT NULL,
`LeavedOn` DATETIME(6) DEFAULT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_UserJoinedServersUpdate`;
CREATE TRIGGER `TR_UserJoinedServersUpdate`
AFTER UPDATE
ON `UserJoinedServers`
FOR EACH ROW
BEGIN
INSERT INTO `UserJoinedServersHistory` (
`JoinId`, `UserId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
)
VALUES (
OLD.JoinId, OLD.UserId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;
DROP TRIGGER IF EXISTS `TR_UserJoinedServersDelete`;
CREATE TRIGGER `TR_UserJoinedServersDelete`
AFTER DELETE
ON `UserJoinedServers`
FOR EACH ROW
BEGIN
INSERT INTO `UserJoinedServersHistory` (
`JoinId`, `UserId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
)
VALUES (
OLD.JoinId, OLD.UserId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;

View File

@ -0,0 +1,52 @@
ALTER TABLE `UserJoinedVoiceChannel`
MODIFY `LastModifiedAt` DATETIME(6) NULL ON UPDATE CURRENT_TIMESTAMP(6);
ALTER TABLE `UserJoinedVoiceChannel`
ALTER COLUMN `CreatedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
ALTER TABLE `UserJoinedVoiceChannel`
ALTER COLUMN `LastModifiedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
CREATE TABLE IF NOT EXISTS `UserJoinedVoiceChannelHistory`
(
`JoinId` BIGINT(20) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`DiscordChannelId` BIGINT(20) NOT NULL,
`JoinedOn` DATETIME(6) NOT NULL,
`LeavedOn` DATETIME(6) DEFAULT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_UserJoinedVoiceChannelUpdate`;
CREATE TRIGGER `TR_UserJoinedVoiceChannelUpdate`
AFTER UPDATE
ON `UserJoinedVoiceChannel`
FOR EACH ROW
BEGIN
INSERT INTO `UserJoinedVoiceChannelHistory` (
`JoinId`, `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
)
VALUES (
OLD.JoinId, OLD.UserId, OLD.DiscordChannelId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6)
);
END;
DROP TRIGGER IF EXISTS `TR_UserJoinedVoiceChannelDelete`;
CREATE TRIGGER `TR_UserJoinedVoiceChannelDelete`
AFTER DELETE
ON `UserJoinedVoiceChannel`
FOR EACH ROW
BEGIN
INSERT INTO `UserJoinedVoiceChannelHistory` (
`JoinId`, `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
)
VALUES (
OLD.JoinId, OLD.UserId, OLD.DiscordChannelId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6)
);
END;

View File

@ -0,0 +1,50 @@
ALTER TABLE `UserMessageCountPerHour`
MODIFY `LastModifiedAt` DATETIME(6) NULL ON UPDATE CURRENT_TIMESTAMP(6);
ALTER TABLE `UserMessageCountPerHour`
ALTER COLUMN `CreatedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
ALTER TABLE `UserMessageCountPerHour`
ALTER COLUMN `LastModifiedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
CREATE TABLE IF NOT EXISTS `UserMessageCountPerHourHistory`
(
`Id` BIGINT(20) NOT NULL,
`Date` DATETIME(6) NOT NULL,
`Hour` BIGINT(20) DEFAULT NULL,
`XPCount` BIGINT(20) DEFAULT NULL,
`UserId` BIGINT(20) DEFAULT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_UserMessageCountPerHourUpdate`;
CREATE TRIGGER `TR_UserMessageCountPerHourUpdate`
AFTER UPDATE
ON `UserMessageCountPerHour`
FOR EACH ROW
BEGIN
INSERT INTO `UserMessageCountPerHourHistory` (
`Id`, `UserId`, `Date`, `Hour`, `XPCount`, `DateFrom`, `DateTo`
)
VALUES (
OLD.Id, OLD.UserId, OLD.Date, OLD.Hour, OLD.XPCount, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;
DROP TRIGGER IF EXISTS `TR_UserMessageCountPerHourDelete`;
CREATE TRIGGER `TR_UserMessageCountPerHourDelete`
AFTER DELETE
ON `UserMessageCountPerHour`
FOR EACH ROW
BEGIN
INSERT INTO `UserMessageCountPerHourHistory` (
`Id`, `UserId`, `Date`, `Hour`, `XPCount`, `Deleted`, `DateFrom`, `DateTo`
)
VALUES (
OLD.Id, OLD.UserId, OLD.Date, OLD.Hour, OLD.XPCount, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;

View File

@ -0,0 +1,49 @@
ALTER TABLE `UserWarnings`
MODIFY `LastModifiedAt` DATETIME(6) NULL ON UPDATE CURRENT_TIMESTAMP(6);
ALTER TABLE `UserWarnings`
ALTER COLUMN `CreatedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
ALTER TABLE `UserWarnings`
ALTER COLUMN `LastModifiedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
CREATE TABLE IF NOT EXISTS `UserWarningsHistory`
(
`Id` BIGINT(20) NOT NULL,
`Description` VARCHAR(255) NOT NULL,
`UserId` BIGINT(20) NOT NULL,
`Author` BIGINT(20) DEFAULT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_UserWarningsUpdate`;
CREATE TRIGGER `TR_UserWarningsUpdate`
AFTER UPDATE
ON `UserWarnings`
FOR EACH ROW
BEGIN
INSERT INTO `UserWarningsHistory` (
`Id`, `Description`, `UserId`, `Author`, `DateFrom`, `DateTo`
)
VALUES (
OLD.Id, OLD.Description, OLD.UserId, OLD.Author, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;
DROP TRIGGER IF EXISTS `TR_UserWarningsDelete`;
CREATE TRIGGER `TR_UserWarningsDelete`
AFTER DELETE
ON `UserWarnings`
FOR EACH ROW
BEGIN
INSERT INTO `UserWarningsHistory` (
`Id`, `Description`, `UserId`, `Author`, `Deleted`, `DateFrom`, `DateTo`
)
VALUES (
OLD.Id, OLD.Description, OLD.UserId, OLD.Author, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;

View File

@ -0,0 +1,49 @@
ALTER TABLE `Users`
MODIFY `LastModifiedAt` DATETIME(6) NULL ON UPDATE CURRENT_TIMESTAMP(6);
ALTER TABLE `Users`
ALTER COLUMN `CreatedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
ALTER TABLE `Users`
ALTER COLUMN `LastModifiedAt` SET DEFAULT CURRENT_TIMESTAMP(6);
CREATE TABLE IF NOT EXISTS `UsersHistory`
(
`UserId` BIGINT(20) NOT NULL,
`DiscordId` BIGINT(20) NOT NULL,
`XP` BIGINT(20) NOT NULL DEFAULT 0,
`ServerId` BIGINT(20) DEFAULT NULL,
`Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
);
DROP TRIGGER IF EXISTS `TR_UsersUpdate`;
CREATE TRIGGER `TR_UsersUpdate`
AFTER UPDATE
ON `Users`
FOR EACH ROW
BEGIN
INSERT INTO `UsersHistory` (
`UserId`, `DiscordId`, `XP`, `ServerId`, `DateFrom`, `DateTo`
)
VALUES (
OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;
DROP TRIGGER IF EXISTS `TR_UsersDelete`;
CREATE TRIGGER `TR_UsersDelete`
AFTER DELETE
ON `Users`
FOR EACH ROW
BEGIN
INSERT INTO `UsersHistory` (
`UserId`, `DiscordId`, `XP`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
)
VALUES (
OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
);
END;

View File

@ -53,7 +53,6 @@ class Client(TableABC):
@sent_message_count.setter
def sent_message_count(self, value: int):
self._modified_at = datetime.now().isoformat()
self._sent_message_count = value
@property
@ -62,7 +61,6 @@ class Client(TableABC):
@received_message_count.setter
def received_message_count(self, value: int):
self._modified_at = datetime.now().isoformat()
self._received_message_count = value
@property
@ -71,7 +69,6 @@ class Client(TableABC):
@deleted_message_count.setter
def deleted_message_count(self, value: int):
self._modified_at = datetime.now().isoformat()
self._deleted_message_count = value
@property
@ -80,7 +77,6 @@ class Client(TableABC):
@received_command_count.setter
def received_command_count(self, value: int):
self._modified_at = datetime.now().isoformat()
self._received_command_count = value
@property
@ -89,7 +85,6 @@ class Client(TableABC):
@moved_users_count.setter
def moved_users_count(self, value: int):
self._modified_at = datetime.now().isoformat()
self._moved_users_count = value
@property

View File

@ -39,7 +39,6 @@ class Level(TableABC):
@name.setter
def name(self, value: str):
self._modified_at = datetime.now().isoformat()
self._name = value
@property
@ -48,7 +47,6 @@ class Level(TableABC):
@color.setter
def color(self, value: str):
self._modified_at = datetime.now().isoformat()
self._color = value
@property
@ -57,7 +55,6 @@ class Level(TableABC):
@min_xp.setter
def min_xp(self, value: int):
self._modified_at = datetime.now().isoformat()
self._min_xp = value
@property
@ -66,7 +63,6 @@ class Level(TableABC):
@permissions.setter
def permissions(self, value: int):
self._modified_at = datetime.now().isoformat()
self._permissions = value
@property
@ -75,7 +71,6 @@ class Level(TableABC):
@server.setter
def server(self, value: Server):
self._modified_at = datetime.now().isoformat()
self._server = value
@staticmethod

View File

@ -71,11 +71,9 @@ class Server(TableABC):
return str(
f"""
INSERT INTO `Servers` (
`DiscordServerId`, `CreatedAt`, `LastModifiedAt`
`DiscordServerId`
) VALUES (
{self._discord_server_id},
'{self._created_at}',
'{self._modified_at}'
{self._discord_server_id}
);
"""
)
@ -85,8 +83,7 @@ class Server(TableABC):
return str(
f"""
UPDATE `Servers`
SET `DiscordServerId` = {self._discord_server_id},
`LastModifiedAt` = '{self._modified_at}'
SET `DiscordServerId` = {self._discord_server_id}
WHERE `ServerId` = {self._server_id};
"""
)

View File

@ -57,7 +57,6 @@ class User(TableABC):
@xp.setter
def xp(self, value: int):
self._modified_at = datetime.now().isoformat()
self._xp = value
@property
@ -152,13 +151,11 @@ class User(TableABC):
return str(
f"""
INSERT INTO `Users` (
`DiscordId`, `XP`, `ServerId`, `CreatedAt`, `LastModifiedAt`
`DiscordId`, `XP`, `ServerId`
) VALUES (
{self._discord_id},
{self._xp},
{self._server.id},
'{self._created_at}',
'{self._modified_at}'
{self._server.id}
);
"""
)
@ -168,8 +165,7 @@ class User(TableABC):
return str(
f"""
UPDATE `Users`
SET `XP` = {self._xp},
`LastModifiedAt` = '{self._modified_at}'
SET `XP` = {self._xp}
WHERE `UserId` = {self._user_id};
"""
)

View File

@ -91,26 +91,18 @@ class UserGameIdent(TableABC):
return str(
f"""
INSERT INTO `UserGameIdents` (
`UserId`, `GameServerId`, `Ident`, `CreatedAt`, `LastModifiedAt`
`UserId`, `GameServerId`, `Ident`
) VALUES (
{self._user.id},
'{self._game_server.id}',
'{self._ident}',
'{self._created_at}',
'{self._modified_at}'
'{self._ident}'
);
"""
)
@property
def udpate_string(self) -> str:
return str(
f"""
UPDATE `UserGameIdents`
SET `LastModifiedAt` = '{self._modified_at}'
WHERE `Id` = {self._id};
"""
)
return ""
@property
def delete_string(self) -> str:

View File

@ -104,14 +104,12 @@ class UserJoinedGameServer(TableABC):
return str(
f"""
INSERT INTO `UserJoinedGameServer` (
`UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
`UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`
) VALUES (
{self._user.id},
'{self._game_server.id}',
'{self._joined_on}',
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
'{self._created_at}',
'{self._modified_at}'
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"}
);
"""
)
@ -121,8 +119,7 @@ class UserJoinedGameServer(TableABC):
return str(
f"""
UPDATE `UserJoinedGameServer`
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
`LastModifiedAt` = '{self._modified_at}'
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"}
WHERE `Id` = {self._id};
"""
)

View File

@ -100,13 +100,11 @@ class UserJoinedServer(TableABC):
return str(
f"""
INSERT INTO `UserJoinedServers` (
`UserId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
`UserId`, `JoinedOn`, `LeavedOn`
) VALUES (
{self._user.id},
'{self._joined_on}',
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
'{self._created_at}',
'{self._modified_at}'
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"}
);
"""
)
@ -116,8 +114,7 @@ class UserJoinedServer(TableABC):
return str(
f"""
UPDATE `UserJoinedServers`
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
`LastModifiedAt` = '{self._modified_at}'
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"}
WHERE `UserId` = {self._user.id};
"""
)

View File

@ -110,14 +110,12 @@ class UserJoinedVoiceChannel(TableABC):
return str(
f"""
INSERT INTO `UserJoinedVoiceChannel` (
`UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
`UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`
) VALUES (
{self._user.id},
{self._channel_id},
'{self._joined_on}',
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
'{self._created_at}',
'{self._modified_at}'
{"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"}
);
"""
)
@ -127,8 +125,7 @@ class UserJoinedVoiceChannel(TableABC):
return str(
f"""
UPDATE `UserJoinedVoiceChannel`
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"},
`LastModifiedAt` = '{self._modified_at}'
SET `LeavedOn` = {"NULL" if self._leaved_on is None else f"'{self._leaved_on}'"}
WHERE `JoinId` = {self._join_id};
"""
)

View File

@ -44,7 +44,6 @@ class UserMessageCountPerHour(TableABC):
@xp_count.setter
def xp_count(self, value: int):
self._modified_at = datetime.now().isoformat()
self._xp_count = value
@property
@ -95,14 +94,12 @@ class UserMessageCountPerHour(TableABC):
return str(
f"""
INSERT INTO `UserMessageCountPerHour` (
`UserId`, `Date`, `Hour`, `XPCount`, `CreatedAt`, `LastModifiedAt`
`UserId`, `Date`, `Hour`, `XPCount`
) VALUES (
{self._user.id},
'{self._date}',
{self._hour},
{self._xp_count},
'{self._created_at}',
'{self._modified_at}'
{self._xp_count}
);
"""
)
@ -112,8 +109,7 @@ class UserMessageCountPerHour(TableABC):
return str(
f"""
UPDATE `UserMessageCountPerHour`
SET `XPCount` = '{self._xp_count}',
`LastModifiedAt` = '{self._modified_at}'
SET `XPCount` = '{self._xp_count}'
WHERE `Id` = {self._id};
"""
)

View File

@ -73,13 +73,11 @@ class UserWarnings(TableABC):
return str(
f"""
INSERT INTO `UserWarnings` (
`Description`, `UserId`, {"" if self._author is None else f"`Author`,"} `CreatedAt`, `LastModifiedAt`
`Description`, `UserId`, `Author`
) VALUES (
'{self._description}',
{self._user.id},
{"" if self._author is None else f"{self._author.id},"}
'{self._created_at}',
'{self._modified_at}'
{"NULL" if self._author is None else f"{self._author.id}"}
);
"""
)
@ -89,8 +87,7 @@ class UserWarnings(TableABC):
return str(
f"""
UPDATE `UserWarnings`
SET `Description` = '{self._description}',
`LastModifiedAt` = '{self._modified_at}'
SET `Description` = '{self._description}'
WHERE `Id` = {self._id};
"""
)