From dc5e5c14407a400f7d85bac7c2a6a9c0c4731890 Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Fri, 3 Mar 2023 19:56:12 -0500 Subject: [PATCH] database: fix event logging table --- core/data/schema/base.py | 7 ++++--- core/data/schema/versions/CORE_2_rollback.sql | 1 + core/data/schema/versions/CORE_3_upgrade.sql | 1 + dbutils.py | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 core/data/schema/versions/CORE_2_rollback.sql create mode 100644 core/data/schema/versions/CORE_3_upgrade.sql diff --git a/core/data/schema/base.py b/core/data/schema/base.py index fd49ac1..955c772 100644 --- a/core/data/schema/base.py +++ b/core/data/schema/base.py @@ -29,6 +29,7 @@ event_log = Table( Column("system", String(255), nullable=False), Column("type", String(255), nullable=False), Column("severity", Integer, nullable=False), + Column("message", String(1000), nullable=False), Column("details", JSON, nullable=False), Column("when_logged", TIMESTAMP, nullable=False, server_default=func.now()), mysql_charset='utf8mb4' @@ -102,12 +103,12 @@ class BaseData(): return None return result.lastrowid - def log_event(self, system: str, type: str, severity: int, details: Dict) -> Optional[int]: - sql = event_log.insert().values(system = system, type = type, severity = severity, details = json.dumps(details)) + def log_event(self, system: str, type: str, severity: int, message: str, details: Dict = {}) -> Optional[int]: + sql = event_log.insert().values(system = system, type = type, severity = severity, message = message, details = json.dumps(details)) result = self.execute(sql) if result is None: - self.logger.error(f"{__name__}: Failed to insert event into event log! system = {system}, type = {type}, severity = {severity}, details = {details}") + self.logger.error(f"{__name__}: Failed to insert event into event log! system = {system}, type = {type}, severity = {severity}, message = {message}") return None return result.lastrowid diff --git a/core/data/schema/versions/CORE_2_rollback.sql b/core/data/schema/versions/CORE_2_rollback.sql new file mode 100644 index 0000000..8944df0 --- /dev/null +++ b/core/data/schema/versions/CORE_2_rollback.sql @@ -0,0 +1 @@ +ALTER TABLE `event_log` DROP COLUMN `message`; \ No newline at end of file diff --git a/core/data/schema/versions/CORE_3_upgrade.sql b/core/data/schema/versions/CORE_3_upgrade.sql new file mode 100644 index 0000000..cc0e8c6 --- /dev/null +++ b/core/data/schema/versions/CORE_3_upgrade.sql @@ -0,0 +1 @@ +ALTER TABLE `event_log` ADD COLUMN `message` VARCHAR(1000) NOT NULL AFTER `severity`; \ No newline at end of file diff --git a/dbutils.py b/dbutils.py index 4500a13..6285e30 100644 --- a/dbutils.py +++ b/dbutils.py @@ -28,7 +28,7 @@ if __name__=='__main__': if args.game is None: data.logger.info("No game set, upgrading core schema") - data.migrate_database("CORE", int(args.version)) + data.migrate_database("CORE", int(args.version), args.action) else: data.migrate_database(args.game, int(args.version), args.action)