From 2f135968858f68a8e53a418806ff7c316ae6750f Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Sat, 15 Jul 2023 00:15:14 -0400 Subject: [PATCH] fix db ignoring port in config, createing database no longer runs over version --- core/data/database.py | 6 +++--- core/data/schema/base.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/data/database.py b/core/data/database.py index 1688812..9fb2606 100644 --- a/core/data/database.py +++ b/core/data/database.py @@ -27,9 +27,9 @@ class Data: if self.config.database.sha2_password: passwd = sha256(self.config.database.password.encode()).digest() - self.__url = f"{self.config.database.protocol}://{self.config.database.username}:{passwd.hex()}@{self.config.database.host}/{self.config.database.name}?charset=utf8mb4" + self.__url = f"{self.config.database.protocol}://{self.config.database.username}:{passwd.hex()}@{self.config.database.host}:{self.config.database.port}/{self.config.database.name}?charset=utf8mb4" else: - self.__url = f"{self.config.database.protocol}://{self.config.database.username}:{self.config.database.password}@{self.config.database.host}/{self.config.database.name}?charset=utf8mb4" + self.__url = f"{self.config.database.protocol}://{self.config.database.username}:{self.config.database.password}@{self.config.database.host}:{self.config.database.port}/{self.config.database.name}?charset=utf8mb4" if Data.engine is None: Data.engine = create_engine(self.__url, pool_recycle=3600) @@ -94,7 +94,7 @@ class Data: game_mod.database(self.config) metadata.create_all(self.__engine.connect()) - self.base.set_schema_ver( + self.base.touch_schema_ver( game_mod.current_schema_version, game_mod.game_codes[0] ) diff --git a/core/data/schema/base.py b/core/data/schema/base.py index 7957301..319101f 100644 --- a/core/data/schema/base.py +++ b/core/data/schema/base.py @@ -102,6 +102,18 @@ class BaseData: return None return row["version"] + + def touch_schema_ver(self, ver: int, game: str = "CORE") -> Optional[int]: + sql = insert(schema_ver).values(game=game, version=ver) + conflict = sql.on_duplicate_key_update(version=schema_ver.c.version) + + result = self.execute(conflict) + if result is None: + self.logger.error( + f"Failed to update schema version for game {game} (v{ver})" + ) + return None + return result.lastrowid def set_schema_ver(self, ver: int, game: str = "CORE") -> Optional[int]: sql = insert(schema_ver).values(game=game, version=ver)