From b56a5f020b77129038ba2ba2e64243135ae13399 Mon Sep 17 00:00:00 2001 From: phantomlan Date: Mon, 13 Nov 2023 03:26:09 +0100 Subject: [PATCH] add rollback sql move GP support to table in DB small fixes --- core/data/schema/versions/SDDT_5_rollback.sql | 22 +++++++ core/data/schema/versions/SDDT_6_upgrade.sql | 10 +++ titles/ongeki/base.py | 65 ++++++------------- titles/ongeki/schema/static.py | 30 ++++++++- 4 files changed, 82 insertions(+), 45 deletions(-) create mode 100644 core/data/schema/versions/SDDT_5_rollback.sql diff --git a/core/data/schema/versions/SDDT_5_rollback.sql b/core/data/schema/versions/SDDT_5_rollback.sql new file mode 100644 index 0000000..08324e0 --- /dev/null +++ b/core/data/schema/versions/SDDT_5_rollback.sql @@ -0,0 +1,22 @@ +SET FOREIGN_KEY_CHECKS=0; + +ALTER TABLE ongeki_user_event_point DROP COLUMN version; +ALTER TABLE ongeki_user_event_point DROP COLUMN rank; +ALTER TABLE ongeki_user_event_point DROP COLUMN type; +ALTER TABLE ongeki_user_event_point DROP COLUMN date; + +ALTER TABLE ongeki_user_tech_event DROP COLUMN version; + +ALTER TABLE ongeki_user_mission_point DROP COLUMN version; + +ALTER TABLE ongeki_static_event DROP COLUMN endDate; + +DROP TABLE ongeki_tech_event_ranking; +DROP TABLE ongeki_static_music_ranking_list; +DROP TABLE ongeki_static_rewards; +DROP TABLE ongeki_static_present_list; +DROP TABLE ongeki_static_tech_music; +DROP TABLE ongeki_static_client_testmode; +DROP TABLE ongeki_static_game_point; + +SET FOREIGN_KEY_CHECKS=1; diff --git a/core/data/schema/versions/SDDT_6_upgrade.sql b/core/data/schema/versions/SDDT_6_upgrade.sql index 3bc6a8e..82d5336 100644 --- a/core/data/schema/versions/SDDT_6_upgrade.sql +++ b/core/data/schema/versions/SDDT_6_upgrade.sql @@ -85,4 +85,14 @@ CREATE TABLE ongeki_static_client_testmode ( minLeverMovable INT NOT NULL, UNIQUE KEY ongeki_static_client_testmode_uk (clientId) ); + +CREATE TABLE ongeki_static_game_point ( + id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, + type INT NOT NULL, + cost INT NOT NULL, + startDate VARCHAR(25) NOT NULL DEFAULT "2000-01-01 05:00:00.0", + endDate VARCHAR(25) NOT NULL DEFAULT "2099-01-01 05:00:00.0", + UNIQUE KEY ongeki_static_game_point_uk (type) +); + SET FOREIGN_KEY_CHECKS=1; diff --git a/titles/ongeki/base.py b/titles/ongeki/base.py index 7e67fd0..2f87b19 100644 --- a/titles/ongeki/base.py +++ b/titles/ongeki/base.py @@ -173,51 +173,28 @@ class OngekiBase: def handle_get_game_point_api_request(self, data: Dict) -> Dict: - """ - Sets the GP amount for A and B sets for 1 - 3 credits - """ - return { - "length": 6, - "gamePointList": [ - { - "type": 0, - "cost": 100, - "startDate": "2000-01-01 05:00:00.0", - "endDate": "2099-01-01 05:00:00.0", - }, - { - "type": 1, - "cost": 230, - "startDate": "2000-01-01 05:00:00.0", - "endDate": "2099-01-01 05:00:00.0", - }, - { - "type": 2, - "cost": 370, - "startDate": "2000-01-01 05:00:00.0", - "endDate": "2099-01-01 05:00:00.0", - }, - { - "type": 3, - "cost": 120, - "startDate": "2000-01-01 05:00:00.0", - "endDate": "2099-01-01 05:00:00.0", - }, - { - "type": 4, - "cost": 240, - "startDate": "2000-01-01 05:00:00.0", - "endDate": "2099-01-01 05:00:00.0", - }, - { - "type": 5, - "cost": 360, - "startDate": "2000-01-01 05:00:00.0", - "endDate": "2099-01-01 05:00:00.0", - }, - ], - } + get_game_point = self.data.static.get_static_game_point() + game_point = [] + if not get_game_point: + self.logger.info(f"GP table is empty, inserting defaults") + self.data.static.put_static_game_point_defaults() + get_game_point = self.data.static.get_static_game_point() + for gp in get_game_point: + tmp = gp._asdict() + game_point.append(tmp) + return { + "length": len(game_point), + "gamePointList": game_point, + } + for gp in get_game_point: + tmp = gp._asdict() + game_point.append(tmp) + return { + "length": len(game_point), + "gamePointList": game_point, + } + def handle_game_login_api_request(self, data: Dict) -> Dict: return {"returnCode": 1, "apiName": "gameLogin"} diff --git a/titles/ongeki/schema/static.py b/titles/ongeki/schema/static.py index 5b459b8..0a5d176 100644 --- a/titles/ongeki/schema/static.py +++ b/titles/ongeki/schema/static.py @@ -134,7 +134,7 @@ present = Table( Column("message", String(255)), Column("startDate", String(25), nullable=False), Column("endDate", String(25), nullable=False), - UniqueConstraint("version", "presentId", "rewardId", name="ongeki_static_present_list_uk"), + UniqueConstraint("version", "presentId", name="ongeki_static_present_list_uk"), mysql_charset="utf8mb4", ) @@ -174,6 +174,18 @@ client_testmode = Table( mysql_charset="utf8mb4", ) +game_point = Table( + "ongeki_static_game_point", + metadata, + Column("id", Integer, primary_key=True, nullable=False), + Column("type", Integer, nullable=False), + Column("cost", Integer, nullable=False), + Column("startDate", String(25), nullable=False, server_default="2000-01-01 05:00:00.0"), + Column("endDate", String(25), nullable=False, server_default="2099-01-01 05:00:00.0"), + UniqueConstraint("type", name="ongeki_static_game_point_uk"), + mysql_charset="utf8mb4", +) + class OngekiStaticData(BaseData): def put_card(self, version: int, card_id: int, **card_data) -> Optional[int]: sql = insert(cards).values(version=version, cardId=card_id, **card_data) @@ -482,3 +494,19 @@ class OngekiStaticData(BaseData): self.logger.warning(f"clientId: {clientId} Failed to update ClientSetting data"), return None return result.lastrowid + + def put_static_game_point_defaults(self) -> Optional[List[Dict]]: + game_point_defaults = [{"type": 0, "cost": 100},{"type": 1, "cost": 230},{"type": 2, "cost": 370},{"type": 3, "cost": 120},{"type": 4, "cost": 240},{"type": 5, "cost": 360}] + sql = insert(game_point).values(game_point_defaults) + result = self.execute(sql) + if result is None: + self.logger.warning(f"Failed to insert default GP table!") + return None + return result.lastrowid + + def get_static_game_point(self) -> Optional[List[Dict]]: + sql = select(game_point.c.type, game_point.c.cost, game_point.c.startDate, game_point.c.endDate) + result = self.execute(sql) + if result is None: + return None + return result.fetchall()