forked from Hay1tsme/artemis
database: fix event logging table
This commit is contained in:
parent
4f3d3d8395
commit
dc5e5c1440
@ -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
|
||||
|
1
core/data/schema/versions/CORE_2_rollback.sql
Normal file
1
core/data/schema/versions/CORE_2_rollback.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE `event_log` DROP COLUMN `message`;
|
1
core/data/schema/versions/CORE_3_upgrade.sql
Normal file
1
core/data/schema/versions/CORE_3_upgrade.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE `event_log` ADD COLUMN `message` VARCHAR(1000) NOT NULL AFTER `severity`;
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user