From 62e52aa4a6bfe9fc657a257cafd7a9f84f9b72fe Mon Sep 17 00:00:00 2001 From: Sheikah45 <66929319+Sheikah45@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:41:06 -0500 Subject: [PATCH] Migrate to supporting database v133 with table removals (#983) * Migrate to supporting database v133 with table removals * Remove unused import * Remove obsolete tests --- .github/workflows/test.yml | 2 +- server/db/models.py | 19 ----- server/player_service.py | 58 -------------- tests/data/test-data.sql | 102 +++++------------------- tests/unit_tests/test_player_service.py | 12 --- 5 files changed, 23 insertions(+), 170 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d67c18f5f..5a5eb1247 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ on: - cron: '0 0 * * *' env: - FAF_DB_VERSION: v122 + FAF_DB_VERSION: v133 FLYWAY_VERSION: 7.5.4 jobs: diff --git a/server/db/models.py b/server/db/models.py index cd5fe3564..9d7378b7c 100644 --- a/server/db/models.py +++ b/server/db/models.py @@ -148,15 +148,6 @@ Column("validity", Integer, nullable=False), ) -global_rating = Table( - "global_rating", metadata, - Column("id", Integer, ForeignKey("login.id"), primary_key=True), - Column("mean", Float), - Column("deviation", Float), - Column("numGames", Integer, nullable=False), - Column("is_active", Boolean, nullable=False), -) - group_permission = Table( "group_permission", metadata, Column("id", Integer, primary_key=True), @@ -188,16 +179,6 @@ Column("last_login", TIMESTAMP) ) -ladder1v1_rating = Table( - "ladder1v1_rating", metadata, - Column("id", Integer, ForeignKey("login.id"), primary_key=True), - Column("mean", Float), - Column("deviation", Float), - Column("numGames", Integer, nullable=False), - Column("winGames", Integer, nullable=False), - Column("is_active", Boolean, nullable=False) -) - leaderboard = Table( "leaderboard", metadata, Column("id", Integer, primary_key=True), diff --git a/server/player_service.py b/server/player_service.py index 158b204b0..a31185aa6 100644 --- a/server/player_service.py +++ b/server/player_service.py @@ -14,7 +14,6 @@ from server.db import FAFDatabase from server.decorators import with_logger from server.players import Player, PlayerState -from server.rating import RatingType from server.timing import at_interval from .core import Service @@ -23,10 +22,8 @@ avatars_list, clan, clan_membership, - global_rating, group_permission, group_permission_assignment, - ladder1v1_rating, leaderboard, leaderboard_rating, login, @@ -149,61 +146,6 @@ async def _fetch_player_ratings(self, player, conn): player.ratings[rating_type] = rating player.game_count[rating_type] = total_games - types_not_found = [ - rating_type for rating_type in ( - RatingType.GLOBAL, RatingType.LADDER_1V1 - ) - if rating_type not in retrieved_ratings - ] - await self._fetch_player_legacy_rating(player, types_not_found, conn) - - async def _fetch_player_legacy_rating(self, player, rating_types, conn): - if not rating_types: - return - - sql = select( - global_rating.c.mean, - global_rating.c.deviation, - global_rating.c.numGames, - ladder1v1_rating.c.mean, - ladder1v1_rating.c.deviation, - ladder1v1_rating.c.numGames, - ).select_from( - login.outerjoin(ladder1v1_rating).outerjoin(global_rating) - ).where( - login.c.id == player.id - ) - result = await conn.execute(sql) - row = result.fetchone() - - if row is None: - self._logger.info("Found no ratings for Player with id %i", player.id) - return - - row = row._mapping - - table_map = { - RatingType.GLOBAL: global_rating, - RatingType.LADDER_1V1: ladder1v1_rating, - } - for rating_type in rating_types: - if rating_type not in table_map: - raise ValueError(f"Unknown rating type {rating_type}.") - - table = table_map[rating_type] - if row[table.c.mean] is None: - self._logger.info( - "Found no %s ratings for Player with id %i", - rating_type, player.id - ) - continue - - player.ratings[rating_type] = ( - row[table.c.mean], - row[table.c.deviation] - ) - player.game_count[rating_type] = row[table.c.numGames] - def remove_player(self, player: Player): if player.id in self._players: del self._players[player.id] diff --git a/tests/data/test-data.sql b/tests/data/test-data.sql index 35fd2e9be..543a5bc49 100644 --- a/tests/data/test-data.sql +++ b/tests/data/test-data.sql @@ -8,11 +8,8 @@ DELETE FROM moderation_report; DELETE FROM teamkills; DELETE FROM unique_id_users; DELETE FROM uniqueid; -DELETE FROM global_rating; -DELETE FROM ladder1v1_rating; DELETE FROM uniqueid_exempt; DELETE FROM friends_and_foes; -DELETE FROM ladder_map; DELETE FROM tutorial; DELETE FROM map_version_review; DELETE FROM map_version_reviews_summary; @@ -25,7 +22,6 @@ DELETE FROM mod_version_reviews_summary; DELETE FROM mod_version; DELETE FROM `mod`; DELETE FROM mod_stats; -DELETE FROM oauth_clients; DELETE FROM updates_faf; DELETE FROM updates_faf_files; DELETE FROM avatars; @@ -38,8 +34,6 @@ DELETE FROM game_review; DELETE FROM game_reviews_summary; DELETE FROM game_stats; DELETE FROM game_featuredMods; -DELETE FROM ladder_division_score; -DELETE FROM ladder_division; DELETE FROM name_history; DELETE FROM user_group_assignment; DELETE FROM login; @@ -136,31 +130,6 @@ insert into leaderboard_rating (login_id, mean, deviation, total_games, leaderbo (106, 900, 75, 20, 3) ; --- legacy table for global rating -insert into global_rating (id, mean, deviation, numGames, is_active) values - (1, 2000, 125, 5, 1), - (2, 1500, 75, 2, 1), - (3, 1650, 62.52, 2, 1), - (50, 1201, 250, 42, 1), - (51, 1201, 250, 42, 1), - (52, 1201, 250, 42, 1), - (100, 1501, 500, 0, 1), - (101, 1501, 500, 0, 1), - (102, 1501, 500, 0, 1) -; - --- legacy ladder rating -insert into ladder1v1_rating (id, mean, deviation, numGames, is_active) values - (1, 2000, 125, 5, 1), - (2, 1500, 75, 2, 1), - (3, 1650, 62.52, 2, 1), - (50, 1301, 400, 12, 1), - (51, 1301, 400, 12, 1), - (100, 1501, 500, 0, 1), - (101, 1501, 500, 0, 1), - (102, 1501, 500, 0, 1) -; - -- UniqueID_exempt insert into uniqueid_exempt (user_id, reason) values (1, 'Because test'); @@ -175,23 +144,23 @@ insert into unique_id_users (user_id, uniqueid_hash) values (2, 'another_id'); insert into unique_id_users (user_id, uniqueid_hash) values (3, 'some_id'); -- Sample maps -insert into map (id, display_name, map_type, battle_type, author) values - (1, 'SCMP_001', 'FFA', 'skirmish', 1), - (2, 'SCMP_002', 'FFA', 'skirmish', 1), - (3, 'SCMP_003', 'FFA', 'skirmish', 1), - (4, 'SCMP_004', 'FFA', 'skirmish', 1), - (5, 'SCMP_005', 'FFA', 'skirmish', 1), - (6, 'SCMP_006', 'FFA', 'skirmish', 2), - (7, 'SCMP_007', 'FFA', 'skirmish', 2), - (8, 'SCMP_008', 'FFA', 'skirmish', 2), - (9, 'SCMP_009', 'FFA', 'skirmish', 2), - (10, 'SCMP_010', 'FFA', 'skirmish', 3), - (11, 'SCMP_011', 'FFA', 'skirmish', 3), - (12, 'SCMP_012', 'FFA', 'skirmish', 3), - (13, 'SCMP_013', 'FFA', 'skirmish', 3), - (14, 'SCMP_014', 'FFA', 'skirmish', 3), - (15, 'SCMP_015', 'FFA', 'skirmish', 3), - (16, 'neroxis_map_generator_sneaky_map', 'FFA', 'skirmish', 1); +insert into map (id, display_name, map_type, battle_type, author, license) values + (1, 'SCMP_001', 'FFA', 'skirmish', 1, 1), + (2, 'SCMP_002', 'FFA', 'skirmish', 1, 1), + (3, 'SCMP_003', 'FFA', 'skirmish', 1, 1), + (4, 'SCMP_004', 'FFA', 'skirmish', 1, 1), + (5, 'SCMP_005', 'FFA', 'skirmish', 1, 1), + (6, 'SCMP_006', 'FFA', 'skirmish', 2, 1), + (7, 'SCMP_007', 'FFA', 'skirmish', 2, 1), + (8, 'SCMP_008', 'FFA', 'skirmish', 2, 1), + (9, 'SCMP_009', 'FFA', 'skirmish', 2, 1), + (10, 'SCMP_010', 'FFA', 'skirmish', 3, 1), + (11, 'SCMP_011', 'FFA', 'skirmish', 3, 1), + (12, 'SCMP_012', 'FFA', 'skirmish', 3, 1), + (13, 'SCMP_013', 'FFA', 'skirmish', 3, 1), + (14, 'SCMP_014', 'FFA', 'skirmish', 3, 1), + (15, 'SCMP_015', 'FFA', 'skirmish', 3, 1), + (16, 'neroxis_map_generator_sneaky_map', 'FFA', 'skirmish', 1, 1); insert into map_version (id, description, max_players, width, height, version, filename, hidden, ranked, map_id) values (1, 'SCMP 001', 8, 1024, 1024, 1, 'maps/scmp_001.zip', 0, 1, 1), @@ -213,10 +182,6 @@ insert into map_version (id, description, max_players, width, height, version, f (17, 'SCMP 015', 8, 512, 512, 3, 'maps/scmp_015.v0003.zip', 0, 1, 15), (18, 'Sneaky_Map', 8, 512, 512, 1, 'maps/neroxis_map_generator_sneaky_map.zip', 0, 0, 16); -insert into ladder_map (id, idmap) values - (1,1), - (2,2); - INSERT INTO `coop_map` (`type`, `name`, `description`, `version`, `filename`) VALUES (0, 'FA Campaign map', 'A map from the FA campaign', 2, 'maps/scmp_coop_123.v0002.zip'), (1, 'Aeon Campaign map', 'A map from the Aeon campaign', 0, 'maps/scmp_coop_124.v0000.zip'), @@ -351,11 +316,11 @@ insert into friends_and_foes (user_id, subject_id, `status`) values (2, 1, 'FRIEND'), (10, 1, 'FRIEND'); -insert into `mod` (id, display_name, author) VALUES - (1, 'test-mod', 'baz'), - (2, 'test-mod2', 'baz'), - (3, 'test-mod3', 'baz'), - (100, 'Mod without icon', 'foo'); +insert into `mod` (id, display_name, author, license) VALUES + (1, 'test-mod', 'baz', 1), + (2, 'test-mod2', 'baz', 1), + (3, 'test-mod3', 'baz', 1), + (100, 'Mod without icon', 'foo', 1); insert into mod_version (id, mod_id, uid, version, description, type, filename, icon) VALUES (1, 1, 'foo', 1, '', 'UI', 'foobar.zip', 'foobar.png'), @@ -411,12 +376,6 @@ insert into clan_membership (clan_id, player_id) values (3, 1), (1, 50); --- sample oauth_client for Postman -insert into oauth_clients (id, name, client_secret, redirect_uris, default_redirect_uri, default_scope) VALUES - ('3bc8282c-7730-11e5-8bcf-feff819cdc9f ', 'Downlord''s FAF Client', '{noop}6035bd78-7730-11e5-8bcf-feff819cdc9f', '', '', 'read_events read_achievements upload_map'), - ('faf-website', 'faf-website', '{noop}banana', 'http://localhost:8020', 'http://localhost:8020', 'public_profile write_account_data create_user'), - ('postman', 'postman', '{noop}postman', 'http://localhost https://www.getpostman.com/oauth2/callback', 'https://www.getpostman.com/oauth2/callback', 'read_events read_achievements upload_map upload_mod write_account_data'); - insert into updates_faf (id, filename, path) values (1, 'ForgedAlliance.exe', 'bin'), (11, 'effects.nx2', 'gamedata'), @@ -447,21 +406,4 @@ insert into mod_version_review (id, text, user_id, score, mod_version_id) VALUES (2, 'Like it', 2, 4, 1), (3, 'Funny', 3, 4, 1); -INSERT INTO ladder_division VALUES - (1, 'League 1 - Division A', 1, 10.0), - (2, 'League 1 - Division B', 1, 30.0), - (3, 'League 1 - Division C', 1, 50.0), - (4, 'League 2 - Division D', 2, 20.0), - (5, 'League 2 - Division E', 2, 60.0), - (6, 'League 2 - Division F', 2, 100.0), - (7, 'League 3 - Division D', 3, 100.0), - (8, 'League 3 - Division E', 3, 200.0), - (9, 'League 3 - Division F', 3, 9999.0); - -INSERT INTO ladder_division_score (season, user_id, league, score, games) VALUES - (1, 1, 1, 9.5, 4), - (1, 2, 1, 49.5, 70), - (1, 3, 2, 0.0, 39), - (1, 4, 3, 10.0, 121); - INSERT INTO email_domain_blacklist VALUES ('spam.org'); diff --git a/tests/unit_tests/test_player_service.py b/tests/unit_tests/test_player_service.py index 1dcf6cf3b..99924ef5a 100644 --- a/tests/unit_tests/test_player_service.py +++ b/tests/unit_tests/test_player_service.py @@ -14,16 +14,6 @@ async def test_fetch_player_data(player_factory, player_service): assert player.avatar == {"url": "https://content.faforever.com/faf/avatars/UEF.png", "tooltip": "UEF"} -async def test_fetch_player_data_legacy_rating(player_factory, player_service): - # Player 51 should only have legacy rating entries, - # but no `leaderboard_rating` entries. - player = player_factory(player_id=51) - - await player_service.fetch_player_data(player) - assert player.ratings[RatingType.GLOBAL] == (1201, 250) - assert player.ratings[RatingType.LADDER_1V1] == (1301, 400) - - async def test_fetch_ratings_nonexistent(player_factory, player_service): player = player_factory(player_id=-1) player_service._logger = mock.Mock() @@ -31,7 +21,6 @@ async def test_fetch_ratings_nonexistent(player_factory, player_service): async with player_service._db.acquire() as conn: await player_service._fetch_player_ratings(player, conn) - player_service._logger.info.assert_called_once() assert player.ratings[RatingType.GLOBAL] == (1500, 500) @@ -44,7 +33,6 @@ async def test_fetch_ratings_partially_nonexistent(player_factory, player_servic async with player_service._db.acquire() as conn: await player_service._fetch_player_ratings(player, conn) - player_service._logger.info.assert_called_once() assert player.ratings[RatingType.LADDER_1V1] == (1500, 500)