diff --git a/.gitignore b/.gitignore index 344ff3b..cd4d4e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ mount/* !mount/.gitkeep +.venv/* +*/.venv/* \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2aa634a..2fc32d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,34 @@ -version: '3' services: mysql: + container_name: database build: - context: . - image: mysql + context: ./mysql + image: bot-detector/mysql:latest environment: - MYSQL_ROOT_PASSWORD=root_bot_buster volumes: - - ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d - - ./mount:/var/lib/mysql + - ./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d + # - ./mysql/mount:/var/lib/mysql # creates persistence ports: - - "127.0.0.1:3306:3306" + - 3307:3306 networks: - botdetector-network + healthcheck: + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + timeout: 20s + retries: 10 + mysql_setup: + container_name: mysql_setup + image: bot-detector/mysql_setup + build: + context: ./mysql_setup + command: ["python", "-u","setup_mysql.py"] + networks: + - botdetector-network + depends_on: + mysql: + condition: service_healthy networks: botdetector-network: - \ No newline at end of file + \ No newline at end of file diff --git a/docker-entrypoint-initdb.d/002_create_schema.sql b/docker-entrypoint-initdb.d/002_create_schema.sql deleted file mode 100644 index 0ee2ea2..0000000 --- a/docker-entrypoint-initdb.d/002_create_schema.sql +++ /dev/null @@ -1,1675 +0,0 @@ --- MySQL Script generated by MySQL Workbench --- Mon Jan 29 19:54:00 2024 --- Model: New Model Version: 1.0 --- MySQL Workbench Forward Engineering - -SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; -SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; -SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; - --- ----------------------------------------------------- --- Schema mydb --- ----------------------------------------------------- --- ----------------------------------------------------- --- Schema playerdata --- ----------------------------------------------------- - --- ----------------------------------------------------- --- Schema playerdata --- ----------------------------------------------------- -CREATE SCHEMA IF NOT EXISTS `playerdata` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci ; -USE `playerdata` ; - --- ----------------------------------------------------- --- Table `playerdata`.`LabelJagex` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`LabelJagex` ( - `id` INT NOT NULL AUTO_INCREMENT, - `label` VARCHAR(50) NOT NULL, - PRIMARY KEY (`id`)) -ENGINE = InnoDB -AUTO_INCREMENT = 7 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`Labels` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`Labels` ( - `id` INT NOT NULL AUTO_INCREMENT, - `label` VARCHAR(50) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL, - PRIMARY KEY (`id`), - UNIQUE INDEX `Unique_label` USING BTREE (`label`) VISIBLE) -ENGINE = InnoDB -AUTO_INCREMENT = 111 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`Players` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`Players` ( - `id` INT NOT NULL AUTO_INCREMENT, - `name` TEXT NOT NULL, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` DATETIME NULL DEFAULT NULL, - `possible_ban` TINYINT(1) NOT NULL DEFAULT '0', - `confirmed_ban` TINYINT(1) NOT NULL DEFAULT '0', - `confirmed_player` TINYINT(1) NOT NULL DEFAULT '0', - `label_id` INT NOT NULL DEFAULT '0', - `label_jagex` INT NOT NULL DEFAULT '0', - `ironman` TINYINT NULL DEFAULT NULL, - `hardcore_ironman` TINYINT NULL DEFAULT NULL, - `ultimate_ironman` TINYINT NULL DEFAULT NULL, - `normalized_name` TEXT NULL DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE INDEX `Unique_name` (`name`(50) ASC) VISIBLE, - INDEX `FK_label_id` (`label_id` ASC) VISIBLE, - INDEX `confirmed_ban_idx` (`confirmed_ban` ASC) VISIBLE, - INDEX `normal_name_index` (`normalized_name`(50) ASC) VISIBLE, - CONSTRAINT `FK_label_id` - FOREIGN KEY (`label_id`) - REFERENCES `playerdata`.`Labels` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -AUTO_INCREMENT = 122610372 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`PlayersChanges` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`PlayersChanges` ( - `id` INT NOT NULL AUTO_INCREMENT, - `ChangeDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `player_id` INT NOT NULL, - `name` VARCHAR(15) NOT NULL, - `created_at` DATETIME NOT NULL, - `updated_at` DATETIME NULL DEFAULT NULL, - `possible_ban` TINYINT(1) NOT NULL DEFAULT '0', - `confirmed_ban` TINYINT(1) NOT NULL DEFAULT '0', - `confirmed_player` TINYINT(1) NOT NULL DEFAULT '0', - `label_id` INT NOT NULL DEFAULT '0', - `label_jagex` INT NOT NULL DEFAULT '0', - PRIMARY KEY (`id`), - INDEX `FK_label_id` (`label_id` ASC) VISIBLE) -ENGINE = InnoDB -AUTO_INCREMENT = 36226947 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`Predictions` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`Predictions` ( - `name` VARCHAR(12) NULL DEFAULT NULL, - `prediction` VARCHAR(50) NULL DEFAULT NULL, - `id` INT NULL DEFAULT NULL, - `created` TIMESTAMP NULL DEFAULT NULL, - `Predicted_confidence` DECIMAL(5,2) NULL DEFAULT NULL, - `Real_Player` DECIMAL(5,2) NULL DEFAULT NULL, - `Unknown_bot` DECIMAL(5,2) NULL DEFAULT '0.00', - `PVM_Melee_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Smithing_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Magic_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Fishing_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Mining_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Crafting_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `PVM_Ranged_Magic_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `PVM_Ranged_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Hunter_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Fletching_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Clue_Scroll_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `LMS_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Agility_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Wintertodt_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Runecrafting_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Zalcano_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Woodcutting_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Thieving_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Soul_Wars_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Cooking_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Vorkath_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Barrows_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Herblore_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Zulrah_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Gauntlet_bot` DECIMAL(5,2) NULL DEFAULT NULL, - `Nex_bot` DECIMAL(5,2) NULL DEFAULT NULL, - UNIQUE INDEX `name` (`name` ASC) VISIBLE, - INDEX `FK_pred_player_id` (`id` ASC) VISIBLE, - CONSTRAINT `FK_pred_player_id` - FOREIGN KEY (`id`) - REFERENCES `playerdata`.`Players` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`Tokens` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`Tokens` ( - `id` INT NOT NULL AUTO_INCREMENT, - `player_name` VARCHAR(50) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL, - `token` VARCHAR(50) NOT NULL, - `request_highscores` TINYINT(1) NOT NULL DEFAULT '0', - `verify_ban` TINYINT(1) NOT NULL DEFAULT '0', - `create_token` TINYINT(1) NOT NULL DEFAULT '0', - `verify_players` TINYINT(1) NOT NULL DEFAULT '0', - `discord_general` TINYINT(1) NOT NULL DEFAULT '0', - PRIMARY KEY (`id`)) -ENGINE = InnoDB -AUTO_INCREMENT = 45 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`PredictionsFeedback` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`PredictionsFeedback` ( - `id` INT NOT NULL AUTO_INCREMENT, - `ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `voter_id` INT NOT NULL, - `subject_id` INT NOT NULL, - `prediction` VARCHAR(50) NOT NULL, - `confidence` FLOAT NOT NULL, - `vote` INT NOT NULL DEFAULT '0', - `feedback_text` TEXT CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL, - `reviewed` TINYINT NOT NULL DEFAULT '0', - `reviewer_id` INT NULL DEFAULT NULL, - `user_notified` TINYINT NOT NULL DEFAULT '0', - `proposed_label` VARCHAR(50) NULL DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE INDEX `Unique_Vote` USING BTREE (`prediction`, `subject_id`, `voter_id`) VISIBLE, - INDEX `Voter_ID` (`voter_id` ASC) VISIBLE, - INDEX `Subject_ID` (`subject_id` ASC) VISIBLE, - INDEX `Reviewer_ID` (`reviewer_id` ASC) VISIBLE, - CONSTRAINT `Reviewer_ID` - FOREIGN KEY (`reviewer_id`) - REFERENCES `playerdata`.`Tokens` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT, - CONSTRAINT `Subject_ID` - FOREIGN KEY (`subject_id`) - REFERENCES `playerdata`.`Players` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT, - CONSTRAINT `Voter_ID` - FOREIGN KEY (`voter_id`) - REFERENCES `playerdata`.`Players` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -AUTO_INCREMENT = 1192895 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`Reports` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`Reports` ( - `ID` BIGINT NOT NULL AUTO_INCREMENT, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `reportedID` INT NOT NULL, - `reportingID` INT NOT NULL, - `region_id` INT NOT NULL, - `x_coord` INT NOT NULL, - `y_coord` INT NOT NULL, - `z_coord` INT NOT NULL, - `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `manual_detect` TINYINT(1) NULL DEFAULT NULL, - `on_members_world` INT NULL DEFAULT NULL, - `on_pvp_world` TINYINT NULL DEFAULT NULL, - `world_number` INT NULL DEFAULT NULL, - `equip_head_id` INT NULL DEFAULT NULL, - `equip_amulet_id` INT NULL DEFAULT NULL, - `equip_torso_id` INT NULL DEFAULT NULL, - `equip_legs_id` INT NULL DEFAULT NULL, - `equip_boots_id` INT NULL DEFAULT NULL, - `equip_cape_id` INT NULL DEFAULT NULL, - `equip_hands_id` INT NULL DEFAULT NULL, - `equip_weapon_id` INT NULL DEFAULT NULL, - `equip_shield_id` INT NULL DEFAULT NULL, - `equip_ge_value` BIGINT NULL DEFAULT NULL, - PRIMARY KEY (`ID`), - UNIQUE INDEX `Unique_Report` (`reportedID` ASC, `reportingID` ASC, `region_id` ASC, `manual_detect` ASC) VISIBLE, - INDEX `idx_reportingID` (`reportingID` ASC) VISIBLE, - INDEX `idx_reportedID_regionDI` (`reportedID` ASC, `region_id` ASC) VISIBLE, - INDEX `idx_heatmap` (`reportedID` ASC, `timestamp` ASC, `region_id` ASC) VISIBLE, - CONSTRAINT `FK_Reported_Players_id` - FOREIGN KEY (`reportedID`) - REFERENCES `playerdata`.`Players` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT, - CONSTRAINT `FK_Reporting_Players_id` - FOREIGN KEY (`reportingID`) - REFERENCES `playerdata`.`Players` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -AUTO_INCREMENT = 10633962610 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`actionQueue` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`actionQueue` ( - `id` INT NOT NULL AUTO_INCREMENT, - `action_type` VARCHAR(50) NOT NULL, - `target_table` VARCHAR(255) NOT NULL, - `target_id` INT NOT NULL, - `begin_time` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, - `end_time` TIMESTAMP NULL DEFAULT NULL, - `processed` TINYINT(1) NULL DEFAULT '0', - PRIMARY KEY (`id`), - INDEX `idx_target_action_processed` (`target_table` ASC, `action_type` ASC, `processed` ASC) VISIBLE, - INDEX `idx_processed_end_time` (`processed` ASC, `end_time` ASC) VISIBLE, - INDEX `idx_processed_begin_time` (`processed` ASC, `begin_time` ASC) VISIBLE, - INDEX `idx_target_table_id` (`target_table` ASC, `action_type` ASC, `target_id` ASC) VISIBLE) -ENGINE = InnoDB -AUTO_INCREMENT = 40084792 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`activeReporters` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`activeReporters` ( - `name` VARCHAR(15) CHARACTER SET 'utf8mb3' NOT NULL, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `migrated` TINYINT(1) NOT NULL DEFAULT '0', - `migrated_at` DATETIME NULL DEFAULT NULL, - PRIMARY KEY (`name`), - INDEX `idx_migrated_name` (`migrated` ASC, `name` ASC) VISIBLE) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`apiPermissions` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`apiPermissions` ( - `id` INT NOT NULL AUTO_INCREMENT, - `permission` TEXT NOT NULL, - PRIMARY KEY (`id`)) -ENGINE = InnoDB -AUTO_INCREMENT = 6 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`apiUser` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`apiUser` ( - `id` INT NOT NULL AUTO_INCREMENT, - `username` TINYTEXT NOT NULL, - `token` TINYTEXT NOT NULL, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `last_used` DATETIME NULL DEFAULT NULL, - `ratelimit` INT NOT NULL DEFAULT '100', - `is_active` TINYINT(1) NOT NULL DEFAULT '1', - PRIMARY KEY (`id`), - INDEX `idx_token` (`token`(15) ASC) VISIBLE) -ENGINE = InnoDB -AUTO_INCREMENT = 41 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`apiUsage` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`apiUsage` ( - `id` BIGINT NOT NULL AUTO_INCREMENT, - `user_id` INT NOT NULL, - `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `route` TEXT NULL DEFAULT NULL, - PRIMARY KEY (`id`), - INDEX `FK_apiUsage_apiUser` (`user_id` ASC) VISIBLE, - CONSTRAINT `FK_apiUsage_apiUser` - FOREIGN KEY (`user_id`) - REFERENCES `playerdata`.`apiUser` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -AUTO_INCREMENT = 3116067 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`apiUserPerms` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`apiUserPerms` ( - `id` INT NOT NULL AUTO_INCREMENT, - `user_id` INT NOT NULL, - `permission_id` INT NOT NULL, - PRIMARY KEY (`id`), - INDEX `FK_apiUserPerms_apiUser` (`user_id` ASC) VISIBLE, - INDEX `FK_apiUserPerms_apiPermission` (`permission_id` ASC) VISIBLE, - CONSTRAINT `FK_apiUserPerms_apiPermission` - FOREIGN KEY (`permission_id`) - REFERENCES `playerdata`.`apiPermissions` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT, - CONSTRAINT `FK_apiUserPerms_apiUser` - FOREIGN KEY (`user_id`) - REFERENCES `playerdata`.`apiUser` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -AUTO_INCREMENT = 85 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`event_log` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`event_log` ( - `id` INT NOT NULL AUTO_INCREMENT, - `created_at` DATETIME NOT NULL, - `event_name` VARCHAR(255) NOT NULL, - `log_metric` VARCHAR(255) NOT NULL, - `log_value` BIGINT NOT NULL, - `log_text` VARCHAR(255) NULL DEFAULT NULL, - `uuid_value` VARCHAR(36) NOT NULL, - PRIMARY KEY (`id`), - INDEX `idx_uuid` USING BTREE (`uuid_value`, `id`) VISIBLE) -ENGINE = InnoDB -AUTO_INCREMENT = 829403 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`gear` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`gear` ( - `equip_head_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `equip_amulet_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `equip_torso_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `equip_legs_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `equip_boots_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `equip_cape_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `equip_hands_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `equip_weapon_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `equip_shield_id` SMALLINT UNSIGNED NULL DEFAULT NULL, - `md5` BINARY(16) GENERATED ALWAYS AS (unhex(md5(concat_ws(_utf8mb4'|',`equip_head_id`,`equip_amulet_id`,`equip_torso_id`,`equip_legs_id`,`equip_boots_id`,`equip_cape_id`,`equip_hands_id`,`equip_weapon_id`,`equip_shield_id`)))) STORED, - PRIMARY KEY (`md5`)) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`labelsJagex` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`labelsJagex` ( - `id` INT NOT NULL DEFAULT '0', - `label` VARCHAR(50) NOT NULL) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`location` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`location` ( - `region_id` INT UNSIGNED NOT NULL, - `x_coord` INT UNSIGNED NOT NULL, - `y_coord` INT UNSIGNED NOT NULL, - `z_coord` INT UNSIGNED NOT NULL, - `md5` BINARY(16) GENERATED ALWAYS AS (unhex(md5(concat_ws(_utf8mb4'|',`region_id`,`x_coord`,`y_coord`,`z_coord`)))) STORED, - PRIMARY KEY (`md5`)) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`migrationState` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`migrationState` ( - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `entity` VARCHAR(50) NOT NULL, - `value_int` BIGINT UNSIGNED NULL DEFAULT NULL, - INDEX `migrationState_created_at_IDX` USING BTREE (`created_at`, `entity`) VISIBLE, - INDEX `idx_entity_created_at` (`entity` ASC, `created_at` ASC) VISIBLE) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`playerHiscoreData` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`playerHiscoreData` ( - `id` BIGINT NOT NULL AUTO_INCREMENT, - `timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `ts_date` DATE NULL DEFAULT NULL, - `Player_id` INT NOT NULL, - `total` BIGINT NULL DEFAULT '0', - `attack` INT NULL DEFAULT '0', - `defence` INT NULL DEFAULT '0', - `strength` INT NULL DEFAULT '0', - `hitpoints` INT NULL DEFAULT '0', - `ranged` INT NULL DEFAULT '0', - `prayer` INT NULL DEFAULT '0', - `magic` INT NULL DEFAULT '0', - `cooking` INT NULL DEFAULT '0', - `woodcutting` INT NULL DEFAULT '0', - `fletching` INT NULL DEFAULT '0', - `fishing` INT NULL DEFAULT '0', - `firemaking` INT NULL DEFAULT '0', - `crafting` INT NULL DEFAULT '0', - `smithing` INT NULL DEFAULT '0', - `mining` INT NULL DEFAULT '0', - `herblore` INT NULL DEFAULT '0', - `agility` INT NULL DEFAULT '0', - `thieving` INT NULL DEFAULT '0', - `slayer` INT NULL DEFAULT '0', - `farming` INT NULL DEFAULT '0', - `runecraft` INT NULL DEFAULT '0', - `hunter` INT NULL DEFAULT '0', - `construction` INT NULL DEFAULT '0', - `league` INT NULL DEFAULT '0', - `bounty_hunter_hunter` INT NULL DEFAULT '0', - `bounty_hunter_rogue` INT NULL DEFAULT '0', - `cs_all` INT NULL DEFAULT '0', - `cs_beginner` INT NULL DEFAULT '0', - `cs_easy` INT NULL DEFAULT '0', - `cs_medium` INT NULL DEFAULT '0', - `cs_hard` INT NULL DEFAULT '0', - `cs_elite` INT NULL DEFAULT '0', - `cs_master` INT NULL DEFAULT '0', - `lms_rank` INT NULL DEFAULT '0', - `soul_wars_zeal` INT NULL DEFAULT '0', - `abyssal_sire` INT NULL DEFAULT '0', - `alchemical_hydra` INT NULL DEFAULT '0', - `barrows_chests` INT NULL DEFAULT '0', - `bryophyta` INT NULL DEFAULT '0', - `callisto` INT NULL DEFAULT '0', - `cerberus` INT NULL DEFAULT '0', - `chambers_of_xeric` INT NULL DEFAULT '0', - `chambers_of_xeric_challenge_mode` INT NULL DEFAULT '0', - `chaos_elemental` INT NULL DEFAULT '0', - `chaos_fanatic` INT NULL DEFAULT '0', - `commander_zilyana` INT NULL DEFAULT '0', - `corporeal_beast` INT NULL DEFAULT '0', - `crazy_archaeologist` INT NULL DEFAULT '0', - `dagannoth_prime` INT NULL DEFAULT '0', - `dagannoth_rex` INT NULL DEFAULT '0', - `dagannoth_supreme` INT NULL DEFAULT '0', - `deranged_archaeologist` INT NULL DEFAULT '0', - `general_graardor` INT NULL DEFAULT '0', - `giant_mole` INT NULL DEFAULT '0', - `grotesque_guardians` INT NULL DEFAULT '0', - `hespori` INT NULL DEFAULT '0', - `kalphite_queen` INT NULL DEFAULT '0', - `king_black_dragon` INT NULL DEFAULT '0', - `kraken` INT NULL DEFAULT '0', - `kreearra` INT NULL DEFAULT '0', - `kril_tsutsaroth` INT NULL DEFAULT '0', - `mimic` INT NULL DEFAULT '0', - `nex` INT NULL DEFAULT '0', - `nightmare` INT NULL DEFAULT '0', - `phosanis_nightmare` INT NULL DEFAULT '0', - `obor` INT NULL DEFAULT '0', - `phantom_muspah` INT NULL DEFAULT '0', - `sarachnis` INT NULL DEFAULT '0', - `scorpia` INT NULL DEFAULT '0', - `skotizo` INT NULL DEFAULT '0', - `tempoross` INT NULL DEFAULT '0', - `the_gauntlet` INT NULL DEFAULT '0', - `the_corrupted_gauntlet` INT NULL DEFAULT '0', - `theatre_of_blood` INT NULL DEFAULT '0', - `theatre_of_blood_hard` INT NULL DEFAULT '0', - `thermonuclear_smoke_devil` INT NULL DEFAULT '0', - `tombs_of_amascut` INT NULL DEFAULT '0', - `tombs_of_amascut_expert` INT NULL DEFAULT '0', - `tzkal_zuk` INT NULL DEFAULT '0', - `tztok_jad` INT NULL DEFAULT '0', - `venenatis` INT NULL DEFAULT '0', - `vetion` INT NULL DEFAULT '0', - `vorkath` INT NULL DEFAULT '0', - `wintertodt` INT NULL DEFAULT '0', - `zalcano` INT NULL DEFAULT '0', - `zulrah` INT NULL DEFAULT '0', - `rifts_closed` INT NULL DEFAULT '0', - `artio` INT NULL DEFAULT '0', - `calvarion` INT NULL DEFAULT '0', - `duke_sucellus` INT NULL DEFAULT '0', - `spindel` INT NULL DEFAULT '0', - `the_leviathan` INT NULL DEFAULT '0', - `the_whisperer` INT NULL DEFAULT '0', - `vardorvis` INT NULL DEFAULT '0', - PRIMARY KEY (`id`), - UNIQUE INDEX `idx_playerHiscoreData_Player_id_timestamp` (`Player_id` ASC, `timestamp` ASC) VISIBLE, - UNIQUE INDEX `Unique_player_date` (`Player_id` ASC, `ts_date` ASC) VISIBLE, - CONSTRAINT `FK_Players_id` - FOREIGN KEY (`Player_id`) - REFERENCES `playerdata`.`Players` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -AUTO_INCREMENT = 2256151476 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`playerHiscoreDataLatest` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`playerHiscoreDataLatest` ( - `id` BIGINT NOT NULL AUTO_INCREMENT, - `timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `ts_date` DATE NULL DEFAULT NULL, - `Player_id` INT NOT NULL, - `total` BIGINT NULL DEFAULT NULL, - `attack` INT NULL DEFAULT NULL, - `defence` INT NULL DEFAULT NULL, - `strength` INT NULL DEFAULT NULL, - `hitpoints` INT NULL DEFAULT NULL, - `ranged` INT NULL DEFAULT NULL, - `prayer` INT NULL DEFAULT NULL, - `magic` INT NULL DEFAULT NULL, - `cooking` INT NULL DEFAULT NULL, - `woodcutting` INT NULL DEFAULT NULL, - `fletching` INT NULL DEFAULT NULL, - `fishing` INT NULL DEFAULT NULL, - `firemaking` INT NULL DEFAULT NULL, - `crafting` INT NULL DEFAULT NULL, - `smithing` INT NULL DEFAULT NULL, - `mining` INT NULL DEFAULT NULL, - `herblore` INT NULL DEFAULT NULL, - `agility` INT NULL DEFAULT NULL, - `thieving` INT NULL DEFAULT NULL, - `slayer` INT NULL DEFAULT NULL, - `farming` INT NULL DEFAULT NULL, - `runecraft` INT NULL DEFAULT NULL, - `hunter` INT NULL DEFAULT NULL, - `construction` INT NULL DEFAULT NULL, - `league` INT NULL DEFAULT NULL, - `bounty_hunter_hunter` INT NULL DEFAULT NULL, - `bounty_hunter_rogue` INT NULL DEFAULT NULL, - `cs_all` INT NULL DEFAULT NULL, - `cs_beginner` INT NULL DEFAULT NULL, - `cs_easy` INT NULL DEFAULT NULL, - `cs_medium` INT NULL DEFAULT NULL, - `cs_hard` INT NULL DEFAULT NULL, - `cs_elite` INT NULL DEFAULT NULL, - `cs_master` INT NULL DEFAULT NULL, - `lms_rank` INT NULL DEFAULT NULL, - `soul_wars_zeal` INT NULL DEFAULT NULL, - `abyssal_sire` INT NULL DEFAULT NULL, - `alchemical_hydra` INT NULL DEFAULT NULL, - `barrows_chests` INT NULL DEFAULT NULL, - `bryophyta` INT NULL DEFAULT NULL, - `callisto` INT NULL DEFAULT NULL, - `cerberus` INT NULL DEFAULT NULL, - `chambers_of_xeric` INT NULL DEFAULT NULL, - `chambers_of_xeric_challenge_mode` INT NULL DEFAULT NULL, - `chaos_elemental` INT NULL DEFAULT NULL, - `chaos_fanatic` INT NULL DEFAULT NULL, - `commander_zilyana` INT NULL DEFAULT NULL, - `corporeal_beast` INT NULL DEFAULT NULL, - `crazy_archaeologist` INT NULL DEFAULT NULL, - `dagannoth_prime` INT NULL DEFAULT NULL, - `dagannoth_rex` INT NULL DEFAULT NULL, - `dagannoth_supreme` INT NULL DEFAULT NULL, - `deranged_archaeologist` INT NULL DEFAULT NULL, - `general_graardor` INT NULL DEFAULT NULL, - `giant_mole` INT NULL DEFAULT NULL, - `grotesque_guardians` INT NULL DEFAULT NULL, - `hespori` INT NULL DEFAULT NULL, - `kalphite_queen` INT NULL DEFAULT NULL, - `king_black_dragon` INT NULL DEFAULT NULL, - `kraken` INT NULL DEFAULT NULL, - `kreearra` INT NULL DEFAULT NULL, - `kril_tsutsaroth` INT NULL DEFAULT NULL, - `mimic` INT NULL DEFAULT NULL, - `nex` INT NULL DEFAULT NULL, - `nightmare` INT NULL DEFAULT NULL, - `phosanis_nightmare` INT NULL DEFAULT NULL, - `obor` INT NULL DEFAULT NULL, - `phantom_muspah` INT NULL DEFAULT NULL, - `sarachnis` INT NULL DEFAULT NULL, - `scorpia` INT NULL DEFAULT NULL, - `skotizo` INT NULL DEFAULT NULL, - `Tempoross` INT NOT NULL, - `the_gauntlet` INT NULL DEFAULT NULL, - `the_corrupted_gauntlet` INT NULL DEFAULT NULL, - `theatre_of_blood` INT NULL DEFAULT NULL, - `theatre_of_blood_hard` INT NULL DEFAULT NULL, - `thermonuclear_smoke_devil` INT NULL DEFAULT NULL, - `tombs_of_amascut` INT NULL DEFAULT NULL, - `tombs_of_amascut_expert` INT NULL DEFAULT NULL, - `tzkal_zuk` INT NULL DEFAULT NULL, - `tztok_jad` INT NULL DEFAULT NULL, - `venenatis` INT NULL DEFAULT NULL, - `vetion` INT NULL DEFAULT NULL, - `vorkath` INT NULL DEFAULT NULL, - `wintertodt` INT NULL DEFAULT NULL, - `zalcano` INT NULL DEFAULT NULL, - `zulrah` INT NULL DEFAULT NULL, - `rifts_closed` INT NULL DEFAULT '0', - `artio` INT NULL DEFAULT '0', - `calvarion` INT NULL DEFAULT '0', - `duke_sucellus` INT NULL DEFAULT '0', - `spindel` INT NULL DEFAULT '0', - `the_leviathan` INT NULL DEFAULT '0', - `the_whisperer` INT NULL DEFAULT '0', - `vardorvis` INT NULL DEFAULT '0', - PRIMARY KEY (`id`), - UNIQUE INDEX `Unique_player` USING BTREE (`Player_id`) VISIBLE, - UNIQUE INDEX `idx_playerHiscoreDataLatest_Player_id_timestamp` (`Player_id` ASC, `timestamp` ASC) VISIBLE, - UNIQUE INDEX `idx_playerHiscoreDataLatest_Player_id_ts_date` (`Player_id` ASC, `ts_date` ASC) VISIBLE, - CONSTRAINT `FK_latest_player` - FOREIGN KEY (`Player_id`) - REFERENCES `playerdata`.`Players` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -AUTO_INCREMENT = 1881668546 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`playerHiscoreDataXPChange` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`playerHiscoreDataXPChange` ( - `id` BIGINT NOT NULL AUTO_INCREMENT, - `timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `ts_date` DATE NULL DEFAULT NULL, - `Player_id` INT NOT NULL, - `total` BIGINT NULL DEFAULT NULL, - `attack` INT NULL DEFAULT NULL, - `defence` INT NULL DEFAULT NULL, - `strength` INT NULL DEFAULT NULL, - `hitpoints` INT NULL DEFAULT NULL, - `ranged` INT NULL DEFAULT NULL, - `prayer` INT NULL DEFAULT NULL, - `magic` INT NULL DEFAULT NULL, - `cooking` INT NULL DEFAULT NULL, - `woodcutting` INT NULL DEFAULT NULL, - `fletching` INT NULL DEFAULT NULL, - `fishing` INT NULL DEFAULT NULL, - `firemaking` INT NULL DEFAULT NULL, - `crafting` INT NULL DEFAULT NULL, - `smithing` INT NULL DEFAULT NULL, - `mining` INT NULL DEFAULT NULL, - `herblore` INT NULL DEFAULT NULL, - `agility` INT NULL DEFAULT NULL, - `thieving` INT NULL DEFAULT NULL, - `slayer` INT NULL DEFAULT NULL, - `farming` INT NULL DEFAULT NULL, - `runecraft` INT NULL DEFAULT NULL, - `hunter` INT NULL DEFAULT NULL, - `construction` INT NULL DEFAULT NULL, - `league` INT NULL DEFAULT NULL, - `bounty_hunter_hunter` INT NULL DEFAULT NULL, - `bounty_hunter_rogue` INT NULL DEFAULT NULL, - `cs_all` INT NULL DEFAULT NULL, - `cs_beginner` INT NULL DEFAULT NULL, - `cs_easy` INT NULL DEFAULT NULL, - `cs_medium` INT NULL DEFAULT NULL, - `cs_hard` INT NULL DEFAULT NULL, - `cs_elite` INT NULL DEFAULT NULL, - `cs_master` INT NULL DEFAULT NULL, - `lms_rank` INT NULL DEFAULT NULL, - `soul_wars_zeal` INT NULL DEFAULT NULL, - `abyssal_sire` INT NULL DEFAULT NULL, - `alchemical_hydra` INT NULL DEFAULT NULL, - `barrows_chests` INT NULL DEFAULT NULL, - `bryophyta` INT NULL DEFAULT NULL, - `callisto` INT NULL DEFAULT NULL, - `cerberus` INT NULL DEFAULT NULL, - `chambers_of_xeric` INT NULL DEFAULT NULL, - `chambers_of_xeric_challenge_mode` INT NULL DEFAULT NULL, - `chaos_elemental` INT NULL DEFAULT NULL, - `chaos_fanatic` INT NULL DEFAULT NULL, - `commander_zilyana` INT NULL DEFAULT NULL, - `corporeal_beast` INT NULL DEFAULT NULL, - `crazy_archaeologist` INT NULL DEFAULT NULL, - `dagannoth_prime` INT NULL DEFAULT NULL, - `dagannoth_rex` INT NULL DEFAULT NULL, - `dagannoth_supreme` INT NULL DEFAULT NULL, - `deranged_archaeologist` INT NULL DEFAULT NULL, - `general_graardor` INT NULL DEFAULT NULL, - `giant_mole` INT NULL DEFAULT NULL, - `grotesque_guardians` INT NULL DEFAULT NULL, - `hespori` INT NULL DEFAULT NULL, - `kalphite_queen` INT NULL DEFAULT NULL, - `king_black_dragon` INT NULL DEFAULT NULL, - `kraken` INT NULL DEFAULT NULL, - `kreearra` INT NULL DEFAULT NULL, - `kril_tsutsaroth` INT NULL DEFAULT NULL, - `mimic` INT NULL DEFAULT NULL, - `nex` INT NULL DEFAULT NULL, - `nightmare` INT NULL DEFAULT NULL, - `obor` INT NULL DEFAULT NULL, - `phantom_muspah` INT NULL DEFAULT NULL, - `phosanis_nightmare` INT NULL DEFAULT NULL, - `sarachnis` INT NULL DEFAULT NULL, - `scorpia` INT NULL DEFAULT NULL, - `skotizo` INT NULL DEFAULT NULL, - `Tempoross` INT NULL DEFAULT NULL, - `the_gauntlet` INT NULL DEFAULT NULL, - `the_corrupted_gauntlet` INT NULL DEFAULT NULL, - `theatre_of_blood` INT NULL DEFAULT NULL, - `theatre_of_blood_hard` INT NULL DEFAULT NULL, - `thermonuclear_smoke_devil` INT NULL DEFAULT NULL, - `tzkal_zuk` INT NULL DEFAULT NULL, - `tztok_jad` INT NULL DEFAULT NULL, - `venenatis` INT NULL DEFAULT NULL, - `vetion` INT NULL DEFAULT NULL, - `vorkath` INT NULL DEFAULT NULL, - `wintertodt` INT NULL DEFAULT NULL, - `zalcano` INT NULL DEFAULT NULL, - `zulrah` INT NULL DEFAULT NULL, - `rifts_closed` INT NULL DEFAULT '0', - `artio` INT NULL DEFAULT '0', - `calvarion` INT NULL DEFAULT '0', - `duke_sucellus` INT NULL DEFAULT '0', - `spindel` INT NULL DEFAULT '0', - `the_leviathan` INT NULL DEFAULT '0', - `the_whisperer` INT NULL DEFAULT '0', - `vardorvis` INT NULL DEFAULT '0', - PRIMARY KEY (`id`), - INDEX `IDX_playerHiscoreDataXPChange_Player_id-timestamp` USING BTREE (`Player_id`, `timestamp`) VISIBLE, - INDEX `IDX_playerHiscoreDataXPChange_Player_id-ts_date` USING BTREE (`Player_id`, `ts_date`) VISIBLE, - CONSTRAINT `fk_phd_xp_pl` - FOREIGN KEY (`Player_id`) - REFERENCES `playerdata`.`Players` (`id`) - ON DELETE RESTRICT - ON UPDATE RESTRICT) -ENGINE = InnoDB -AUTO_INCREMENT = 1489416008 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`regionIDNames` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`regionIDNames` ( - `entry_ID` INT NOT NULL AUTO_INCREMENT, - `region_ID` INT NOT NULL, - `z_axis` INT NULL DEFAULT '0', - `region_name` TEXT NOT NULL, - PRIMARY KEY (`entry_ID`), - UNIQUE INDEX `region_ID` (`region_ID` ASC) VISIBLE) -ENGINE = InnoDB -AUTO_INCREMENT = 27180 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`sighting` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`sighting` ( - `reported_id` INT NOT NULL, - `reporting_id` INT NOT NULL, - `manual_detect` TINYINT(1) NULL DEFAULT NULL, - `md5` BINARY(16) GENERATED ALWAYS AS (unhex(md5(concat_ws(_utf8mb4'|',`reported_id`,`reporting_id`,`manual_detect`)))) STORED, - PRIMARY KEY (`md5`)) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`world` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`world` ( - `world_number` SMALLINT UNSIGNED NULL DEFAULT NULL, - `members_world` TINYINT(1) NULL DEFAULT NULL, - `pvp_world` TINYINT(1) NULL DEFAULT NULL, - `md5` BINARY(16) GENERATED ALWAYS AS (unhex(md5(concat_ws(_utf8mb4'|',`world_number`,`members_world`,`pvp_world`)))) STORED, - PRIMARY KEY (`md5`)) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`report` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`report` ( - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `sighting_md5` BINARY(16) NULL DEFAULT NULL, - `location_md5` BINARY(16) NULL DEFAULT NULL, - `world_md5` BINARY(16) NULL DEFAULT NULL, - `gear_md5` BINARY(16) NULL DEFAULT NULL, - `md5` BINARY(16) NOT NULL, - `equip_ge_value` BIGINT UNSIGNED NULL DEFAULT NULL, - PRIMARY KEY (`md5`), - INDEX `idx_sighting_location_md5` (`sighting_md5` ASC, `location_md5` ASC) VISIBLE, - INDEX `idx_location_md5` (`location_md5` ASC) VISIBLE, - INDEX `idx_world_md5` (`world_md5` ASC) VISIBLE, - INDEX `idx_gear_md5` (`gear_md5` ASC) VISIBLE, - CONSTRAINT `report_ibfk_1` - FOREIGN KEY (`sighting_md5`) - REFERENCES `playerdata`.`sighting` (`md5`), - CONSTRAINT `report_ibfk_2` - FOREIGN KEY (`location_md5`) - REFERENCES `playerdata`.`location` (`md5`), - CONSTRAINT `report_ibfk_3` - FOREIGN KEY (`world_md5`) - REFERENCES `playerdata`.`world` (`md5`), - CONSTRAINT `report_ibfk_4` - FOREIGN KEY (`gear_md5`) - REFERENCES `playerdata`.`gear` (`md5`)) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`reportLatest` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`reportLatest` ( - `report_id` BIGINT NULL DEFAULT NULL, - `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, - `reported_id` INT NOT NULL, - `region_id` INT NOT NULL, - `x_coord` INT NOT NULL, - `y_coord` INT NOT NULL, - `z_coord` INT NOT NULL, - `timestamp` TIMESTAMP NOT NULL, - `on_members_world` INT NULL DEFAULT NULL, - `world_number` INT NULL DEFAULT NULL, - `equip_head_id` INT NULL DEFAULT NULL, - `equip_amulet_id` INT NULL DEFAULT NULL, - `equip_torso_id` INT NULL DEFAULT NULL, - `equip_legs_id` INT NULL DEFAULT NULL, - `equip_boots_id` INT NULL DEFAULT NULL, - `equip_cape_id` INT NULL DEFAULT NULL, - `equip_hands_id` INT NULL DEFAULT NULL, - `equip_weapon_id` INT NULL DEFAULT NULL, - `equip_shield_id` INT NULL DEFAULT NULL, - `equip_ge_value` BIGINT NULL DEFAULT NULL, - PRIMARY KEY (`reported_id`)) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`reportRecordsBanned` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`reportRecordsBanned` ( - `_table` VARCHAR(7) NOT NULL DEFAULT '', - `_count` BIGINT NOT NULL DEFAULT '0') -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`stgReports` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`stgReports` ( - `ID` BIGINT NOT NULL AUTO_INCREMENT, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `reportedID` INT NOT NULL, - `reportingID` INT NOT NULL, - `region_id` INT NOT NULL, - `x_coord` INT NOT NULL, - `y_coord` INT NOT NULL, - `z_coord` INT NOT NULL, - `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `manual_detect` TINYINT(1) NULL DEFAULT NULL, - `on_members_world` INT NULL DEFAULT NULL, - `on_pvp_world` TINYINT NULL DEFAULT NULL, - `world_number` INT NULL DEFAULT NULL, - `equip_head_id` INT NULL DEFAULT NULL, - `equip_amulet_id` INT NULL DEFAULT NULL, - `equip_torso_id` INT NULL DEFAULT NULL, - `equip_legs_id` INT NULL DEFAULT NULL, - `equip_boots_id` INT NULL DEFAULT NULL, - `equip_cape_id` INT NULL DEFAULT NULL, - `equip_hands_id` INT NULL DEFAULT NULL, - `equip_weapon_id` INT NULL DEFAULT NULL, - `equip_shield_id` INT NULL DEFAULT NULL, - `equip_ge_value` BIGINT NULL DEFAULT NULL, - PRIMARY KEY (`ID`)) -ENGINE = InnoDB -AUTO_INCREMENT = 20530843679 -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - - --- ----------------------------------------------------- --- Table `playerdata`.`xx_stats` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `playerdata`.`xx_stats` ( - `player_count` BIGINT NOT NULL DEFAULT '0', - `confirmed_ban` TINYINT(1) NOT NULL DEFAULT '0', - `confirmed_player` TINYINT(1) NOT NULL DEFAULT '0', - `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP) -ENGINE = InnoDB -DEFAULT CHARACTER SET = utf8mb4 -COLLATE = utf8mb4_0900_ai_ci; - -USE `playerdata`; - -DELIMITER $$ -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`localhost` -TRIGGER `playerdata`.`trg_missing_normalized_name` -BEFORE INSERT ON `playerdata`.`Players` -FOR EACH ROW -BEGIN - IF (new.normalized_name is NULL) THEN - SET new.normalized_name = TRIM(REPLACE(REPLACE(LOWER(new.name), '_',' '),'-',' ')); - END IF; - END$$ - -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`localhost` -TRIGGER `playerdata`.`trg_players_changes` -AFTER UPDATE ON `playerdata`.`Players` -FOR EACH ROW -BEGIN - IF 1=2 - or new.possible_ban != old.possible_ban - or new.confirmed_ban != old.confirmed_ban - or new.confirmed_player != old.confirmed_player - or new.label_id != old.label_id - or new.label_jagex != old.label_jagex - THEN - INSERT ignore INTO PlayersChanges - (player_id, name, created_at, updated_at, possible_ban, confirmed_ban, confirmed_player, label_id, label_jagex) - VALUES - (new.id, new.name, new.created_at, new.updated_at, new.possible_ban, new.confirmed_ban, new.confirmed_player, new.label_id, new.label_jagex); - END IF; -END$$ - -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`localhost` -TRIGGER `playerdata`.`report_latest_AfterInsert` -AFTER INSERT ON `playerdata`.`Reports` -FOR EACH ROW -BEGIN - insert INTO reportLatest( - report_id, - reported_id, - region_id, - x_coord, - y_coord, - z_coord, - timestamp, - on_members_world, - world_number, - equip_head_id, - equip_amulet_id, - equip_torso_id, - equip_legs_id, - equip_boots_id, - equip_cape_id, - equip_hands_id, - equip_weapon_id, - equip_shield_id, - equip_ge_value - ) - values ( - new.ID, - new.reportedID, - new.region_id, - new.x_coord, - new.y_coord, - new.z_coord, - new.timestamp, - new.on_members_world, - new.world_number, - new.equip_head_id, - new.equip_amulet_id, - new.equip_torso_id, - new.equip_legs_id, - new.equip_boots_id, - new.equip_cape_id, - new.equip_hands_id, - new.equip_weapon_id, - new.equip_shield_id, - new.equip_ge_value - ) - on duplicate key update - report_id = new.ID, - reported_id = new.reportedID , - region_id = new.region_id , - x_coord = new.x_coord , - y_coord = new.y_coord , - z_coord = new.z_coord , - timestamp = new.timestamp , - on_members_world = new.on_members_world, - world_number = new.world_number, - equip_head_id = new.equip_head_id, - equip_amulet_id = new.equip_amulet_id, - equip_torso_id = new.equip_torso_id, - equip_legs_id = new.equip_legs_id, - equip_boots_id = new.equip_boots_id, - equip_cape_id = new.equip_cape_id, - equip_hands_id = new.equip_hands_id, - equip_weapon_id = new.equip_weapon_id, - equip_shield_id = new.equip_shield_id, - equip_ge_value = new.equip_ge_value - ; -END$$ - -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`%` -TRIGGER `playerdata`.`trg_playerHiscoreData_keep_latest` -AFTER INSERT ON `playerdata`.`playerHiscoreData` -FOR EACH ROW -BEGIN - DECLARE player_count INT; - DECLARE delete_limit INT; - - -- Count the number of records for the current player - SELECT COUNT(*) INTO player_count - FROM playerHiscoreData - WHERE Player_id = NEW.Player_id; - - -- If the count exceeds 30, set the delete limit - IF player_count > 30 THEN - SET delete_limit = player_count - 30; - - -- Insert a delete action into actionQueue - INSERT INTO actionQueue (target_table, action_type, target_id) - SELECT - 'playerHiscoreData', 'DELETE', ID - FROM playerHiscoreData - WHERE Player_id = NEW.Player_id - ORDER BY timestamp ASC - LIMIT delete_limit; - END IF; -END$$ - -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`%` -TRIGGER `playerdata`.`trg_playerHiscoreData_sync_trigger` -AFTER INSERT ON `playerdata`.`playerHiscoreData` -FOR EACH ROW -BEGIN - insert into playerdata.playerHiscoreDataLatest ( - ts_date, - timestamp, - Player_id, - total, - attack, - defence, - strength, - hitpoints, - ranged, - prayer, - magic, - cooking, - woodcutting, - fletching, - fishing, - firemaking, - crafting, - smithing, - mining, - herblore, - agility, - thieving, - slayer, - farming, - runecraft, - hunter, - construction, - league, - bounty_hunter_hunter, - bounty_hunter_rogue, - cs_all, - cs_beginner, - cs_easy, - cs_medium, - cs_hard, - cs_elite, - cs_master, - lms_rank, - soul_wars_zeal, - abyssal_sire, - alchemical_hydra, - barrows_chests, - bryophyta, - callisto, - cerberus, - chambers_of_xeric, - chambers_of_xeric_challenge_mode, - chaos_elemental, - chaos_fanatic, - commander_zilyana, - corporeal_beast, - crazy_archaeologist, - dagannoth_prime, - dagannoth_rex, - dagannoth_supreme, - deranged_archaeologist, - general_graardor, - giant_mole, - grotesque_guardians, - hespori, - kalphite_queen, - king_black_dragon, - kraken, - kreearra, - kril_tsutsaroth, - mimic, - nex, - nightmare, - phosanis_nightmare, - obor, - phantom_muspah, - sarachnis, - scorpia, - skotizo, - Tempoross, - the_gauntlet, - the_corrupted_gauntlet, - theatre_of_blood, - theatre_of_blood_hard, - thermonuclear_smoke_devil, - tombs_of_amascut, - tombs_of_amascut_expert, - tzkal_zuk, - tztok_jad, - venenatis, - vetion, - vorkath, - wintertodt, - zalcano, - zulrah, - rifts_closed, - artio, - calvarion, - duke_sucellus, - spindel, - the_leviathan, - the_whisperer, - vardorvis - ) values ( - NEW.ts_date, - NEW.timestamp, - NEW.Player_id, - NEW.total, - NEW.attack, - NEW.defence, - NEW.strength, - NEW.hitpoints, - NEW.ranged, - NEW.prayer, - NEW.magic, - NEW.cooking, - NEW.woodcutting, - NEW.fletching, - NEW.fishing, - NEW.firemaking, - NEW.crafting, - NEW.smithing, - NEW.mining, - NEW.herblore, - NEW.agility, - NEW.thieving, - NEW.slayer, - NEW.farming, - NEW.runecraft, - NEW.hunter, - NEW.construction, - NEW.league, - NEW.bounty_hunter_hunter, - NEW.bounty_hunter_rogue, - NEW.cs_all, - NEW.cs_beginner, - NEW.cs_easy, - NEW.cs_medium, - NEW.cs_hard, - NEW.cs_elite, - NEW.cs_master, - NEW.lms_rank, - NEW.soul_wars_zeal, - NEW.abyssal_sire, - NEW.alchemical_hydra, - NEW.barrows_chests, - NEW.bryophyta, - NEW.callisto, - NEW.cerberus, - NEW.chambers_of_xeric, - NEW.chambers_of_xeric_challenge_mode, - NEW.chaos_elemental, - NEW.chaos_fanatic, - NEW.commander_zilyana, - NEW.corporeal_beast, - NEW.crazy_archaeologist, - NEW.dagannoth_prime, - NEW.dagannoth_rex, - NEW.dagannoth_supreme, - NEW.deranged_archaeologist, - NEW.general_graardor, - NEW.giant_mole, - NEW.grotesque_guardians, - NEW.hespori, - NEW.kalphite_queen, - NEW.king_black_dragon, - NEW.kraken, - NEW.kreearra, - NEW.kril_tsutsaroth, - NEW.mimic, - NEW.nex, - NEW.nightmare, - NEW.phosanis_nightmare, - NEW.obor, - NEW.phantom_muspah, - NEW.sarachnis, - NEW.scorpia, - NEW.skotizo, - NEW.Tempoross, - NEW.the_gauntlet, - NEW.the_corrupted_gauntlet, - NEW.theatre_of_blood, - NEW.theatre_of_blood_hard, - NEW.thermonuclear_smoke_devil, - NEW.tombs_of_amascut, - NEW.tombs_of_amascut_expert, - NEW.tzkal_zuk, - NEW.tztok_jad, - NEW.venenatis, - NEW.vetion, - NEW.vorkath, - NEW.wintertodt, - NEW.zalcano, - NEW.zulrah, - NEW.rifts_closed, - NEW.artio, - NEW.calvarion, - NEW.duke_sucellus, - NEW.spindel, - NEW.the_leviathan, - NEW.the_whisperer, - NEW.vardorvis - ) ON DUPLICATE KEY UPDATE - ts_date = NEW.ts_date, - timestamp = NEW.timestamp, - Player_id = NEW.Player_id, - total = NEW.total, - attack = NEW.attack, - defence = NEW.defence, - strength = NEW.strength, - hitpoints = NEW.hitpoints, - ranged = NEW.ranged, - prayer = NEW.prayer, - magic = NEW.magic, - cooking = NEW.cooking, - woodcutting = NEW.woodcutting, - fletching = NEW.fletching, - fishing = NEW.fishing, - firemaking = NEW.firemaking, - crafting = NEW.crafting, - smithing = NEW.smithing, - mining = NEW.mining, - herblore = NEW.herblore, - agility = NEW.agility, - thieving = NEW.thieving, - slayer = NEW.slayer, - farming = NEW.farming, - runecraft = NEW.runecraft, - hunter = NEW.hunter, - construction = NEW.construction, - league = NEW.league, - bounty_hunter_hunter = NEW.bounty_hunter_hunter, - bounty_hunter_rogue = NEW.bounty_hunter_rogue, - cs_all = NEW.cs_all, - cs_beginner = NEW.cs_beginner, - cs_easy = NEW.cs_easy, - cs_medium = NEW.cs_medium, - cs_hard = NEW.cs_hard, - cs_elite = NEW.cs_elite, - cs_master = NEW.cs_master, - lms_rank = NEW.lms_rank, - soul_wars_zeal = NEW.soul_wars_zeal, - abyssal_sire = NEW.abyssal_sire, - alchemical_hydra = NEW.alchemical_hydra, - barrows_chests = NEW.barrows_chests, - bryophyta = NEW.bryophyta, - callisto = NEW.callisto, - cerberus = NEW.cerberus, - chambers_of_xeric = NEW.chambers_of_xeric, - chambers_of_xeric_challenge_mode = NEW.chambers_of_xeric_challenge_mode, - chaos_elemental = NEW.chaos_elemental, - chaos_fanatic = NEW.chaos_fanatic, - commander_zilyana = NEW.commander_zilyana, - corporeal_beast = NEW.corporeal_beast, - crazy_archaeologist = NEW.crazy_archaeologist, - dagannoth_prime = NEW.dagannoth_prime, - dagannoth_rex = NEW.dagannoth_rex, - dagannoth_supreme = NEW.dagannoth_supreme, - deranged_archaeologist = NEW.deranged_archaeologist, - general_graardor = NEW.general_graardor, - giant_mole = NEW.giant_mole, - grotesque_guardians = NEW.grotesque_guardians, - hespori = NEW.hespori, - kalphite_queen = NEW.kalphite_queen, - king_black_dragon = NEW.king_black_dragon, - kraken = NEW.kraken, - kreearra = NEW.kreearra, - kril_tsutsaroth = NEW.kril_tsutsaroth, - mimic = NEW.mimic, - nex = NEW.nex, - nightmare = NEW.nightmare, - phosanis_nightmare = NEW.phosanis_nightmare, - obor = NEW.obor, - phantom_muspah = NEW.phantom_muspah, - sarachnis = NEW.sarachnis, - scorpia = NEW.scorpia, - skotizo = NEW.skotizo, - Tempoross = NEW.Tempoross, - the_gauntlet = NEW.the_gauntlet, - the_corrupted_gauntlet = NEW.the_corrupted_gauntlet, - theatre_of_blood = NEW.theatre_of_blood, - theatre_of_blood_hard = NEW.theatre_of_blood_hard, - thermonuclear_smoke_devil = NEW.thermonuclear_smoke_devil, - tombs_of_amascut = NEW.tombs_of_amascut, - tombs_of_amascut_expert = NEW.tombs_of_amascut_expert, - tzkal_zuk = NEW.tzkal_zuk, - tztok_jad = NEW.tztok_jad, - venenatis = NEW.venenatis, - vetion = NEW.vetion, - vorkath = NEW.vorkath, - wintertodt = NEW.wintertodt, - zalcano = NEW.zalcano, - zulrah = NEW.zulrah, - rifts_closed = NEW.rifts_closed, - artio = NEW.artio, - calvarion = NEW.calvarion, - duke_sucellus = NEW.duke_sucellus, - spindel = NEW.spindel, - the_leviathan = NEW.the_leviathan, - the_whisperer = NEW.the_whisperer, - vardorvis = NEW.vardorvis -; -END$$ - -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`localhost` -TRIGGER `playerdata`.`trg_playerHiscoreData_ts_date_before_insert` -BEFORE INSERT ON `playerdata`.`playerHiscoreData` -FOR EACH ROW -SET new.ts_date = DATE(new.timestamp)$$ - -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`%` -TRIGGER `playerdata`.`trg_update_actionQueue_after_playerHiscoreData_delete` -AFTER DELETE ON `playerdata`.`playerHiscoreData` -FOR EACH ROW -BEGIN - UPDATE actionQueue - SET - processed = TRUE, - end_time = CURRENT_TIMESTAMP - WHERE 1=1 - AND target_table = 'playerHiscoreData' - AND action_type = 'DELETE' - AND target_id = OLD.id; -END$$ - -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`%` -TRIGGER `playerdata`.`playerHiscoreDataLatest_AFTER_UPDATE` -AFTER UPDATE ON `playerdata`.`playerHiscoreDataLatest` -FOR EACH ROW -BEGIN - INSERT IGNORE INTO playerdata.playerHiscoreDataXPChange( - ts_date, - timestamp, - Player_id, - total, - attack, - defence, - strength, - hitpoints, - ranged, - prayer, - magic, - cooking, - woodcutting, - fletching, - fishing, - firemaking, - crafting, - smithing, - mining, - herblore, - agility, - thieving, - slayer, - farming, - runecraft, - hunter, - construction, - league, - bounty_hunter_hunter, - bounty_hunter_rogue, - cs_all, - cs_beginner, - cs_easy, - cs_medium, - cs_hard, - cs_elite, - cs_master, - lms_rank, - soul_wars_zeal, - abyssal_sire, - alchemical_hydra, - barrows_chests, - bryophyta, - callisto, - cerberus, - chambers_of_xeric, - chambers_of_xeric_challenge_mode, - chaos_elemental, - chaos_fanatic, - commander_zilyana, - corporeal_beast, - crazy_archaeologist, - dagannoth_prime, - dagannoth_rex, - dagannoth_supreme, - deranged_archaeologist, - general_graardor, - giant_mole, - grotesque_guardians, - hespori, - kalphite_queen, - king_black_dragon, - kraken, - kreearra, - kril_tsutsaroth, - mimic, - nex, - nightmare, - phosanis_nightmare, - obor, - phantom_muspah, - sarachnis, - scorpia, - skotizo, - Tempoross, - the_gauntlet, - the_corrupted_gauntlet, - theatre_of_blood, - theatre_of_blood_hard, - thermonuclear_smoke_devil, - -- tombs_of_amascut, - -- tombs_of_amascut_expert, - tzkal_zuk, - tztok_jad, - venenatis, - vetion, - vorkath, - wintertodt, - zalcano, - zulrah, - rifts_closed, - artio, - calvarion, - duke_sucellus, - spindel, - the_leviathan, - the_whisperer, - vardorvis - ) - VALUES ( - NEW.ts_date, - NEW.timestamp, - NEW.Player_id, - NEW.total - OLD.total, - NEW.attack - OLD.attack, - NEW.defence - OLD.defence, - NEW.strength - OLD.strength, - NEW.hitpoints - OLD.hitpoints, - NEW.ranged - OLD.ranged, - NEW.prayer - OLD.prayer, - NEW.magic - OLD.magic, - NEW.cooking - OLD.cooking, - NEW.woodcutting - OLD.woodcutting, - NEW.fletching - OLD.fletching, - NEW.fishing - OLD.fishing, - NEW.firemaking - OLD.firemaking, - NEW.crafting - OLD.crafting, - NEW.smithing - OLD.smithing, - NEW.mining - OLD.mining, - NEW.herblore - OLD.herblore, - NEW.agility - OLD.agility, - NEW.thieving - OLD.thieving, - NEW.slayer - OLD.slayer, - NEW.farming - OLD.farming, - NEW.runecraft - OLD.runecraft, - NEW.hunter - OLD.hunter, - NEW.construction - OLD.construction, - NEW.league - OLD.league, - NEW.bounty_hunter_hunter - OLD.bounty_hunter_hunter, - NEW.bounty_hunter_rogue - OLD.bounty_hunter_rogue, - NEW.cs_all - OLD.cs_all, - NEW.cs_beginner - OLD.cs_beginner, - NEW.cs_easy - OLD.cs_easy, - NEW.cs_medium - OLD.cs_medium, - NEW.cs_hard - OLD.cs_hard, - NEW.cs_elite - OLD.cs_elite, - NEW.cs_master - OLD.cs_master, - NEW.lms_rank - OLD.lms_rank, - NEW.soul_wars_zeal - OLD.soul_wars_zeal, - NEW.abyssal_sire - OLD.abyssal_sire, - NEW.alchemical_hydra - OLD.alchemical_hydra, - NEW.barrows_chests - OLD.barrows_chests, - NEW.bryophyta - OLD.bryophyta, - NEW.callisto - OLD.callisto, - NEW.cerberus - OLD.cerberus, - NEW.chambers_of_xeric - OLD.chambers_of_xeric, - NEW.chambers_of_xeric_challenge_mode - OLD.chambers_of_xeric_challenge_mode, - NEW.chaos_elemental - OLD.chaos_elemental, - NEW.chaos_fanatic - OLD.chaos_fanatic, - NEW.commander_zilyana - OLD.commander_zilyana, - NEW.corporeal_beast - OLD.corporeal_beast, - NEW.crazy_archaeologist - OLD.crazy_archaeologist, - NEW.dagannoth_prime - OLD.dagannoth_prime, - NEW.dagannoth_rex - OLD.dagannoth_rex, - NEW.dagannoth_supreme - OLD.dagannoth_supreme, - NEW.deranged_archaeologist - OLD.deranged_archaeologist, - NEW.general_graardor - OLD.general_graardor, - NEW.giant_mole - OLD.giant_mole, - NEW.grotesque_guardians - OLD.grotesque_guardians, - NEW.hespori - OLD.hespori, - NEW.kalphite_queen - OLD.kalphite_queen, - NEW.king_black_dragon - OLD.king_black_dragon, - NEW.kraken - OLD.kraken, - NEW.kreearra - OLD.kreearra, - NEW.kril_tsutsaroth - OLD.kril_tsutsaroth, - NEW.mimic - OLD.mimic, - NEW.nex - OLD.nex, - NEW.nightmare - OLD.nightmare, - NEW.phosanis_nightmare - OLD.phosanis_nightmare, - NEW.obor - OLD.obor, - NEW.phantom_muspah - OLD.phantom_muspah, - NEW.sarachnis - OLD.sarachnis, - NEW.scorpia - OLD.scorpia, - NEW.skotizo - OLD.skotizo, - NEW.Tempoross - OLD.Tempoross, - NEW.the_gauntlet - OLD.the_gauntlet, - NEW.the_corrupted_gauntlet - OLD.the_corrupted_gauntlet, - NEW.theatre_of_blood - OLD.theatre_of_blood, - NEW.theatre_of_blood_hard - OLD.theatre_of_blood_hard, - NEW.thermonuclear_smoke_devil - OLD.thermonuclear_smoke_devil, - -- NEW.tombs_of_amascut - OLD.tombs_of_amascut, - -- NEW.tombs_of_amascut_expert - OLD.tombs_of_amascut_expert, - NEW.tzkal_zuk - OLD.tzkal_zuk, - NEW.tztok_jad - OLD.tztok_jad, - NEW.venenatis - OLD.venenatis, - NEW.vetion - OLD.vetion, - NEW.vorkath - OLD.vorkath, - NEW.wintertodt - OLD.wintertodt, - NEW.zalcano - OLD.zalcano, - NEW.zulrah - OLD.zulrah, - NEW.rifts_closed - OLD.rifts_closed, - NEW.artio - OLD.artio, - NEW.calvarion - OLD.calvarion, - NEW.duke_sucellus - OLD.duke_sucellus, - NEW.spindel - OLD.spindel, - NEW.the_leviathan - OLD.the_leviathan, - NEW.the_whisperer - OLD.the_whisperer, - NEW.vardorvis - OLD.vardorvis - ); -END$$ - -USE `playerdata`$$ -CREATE -DEFINER=`event_admin`@`%` -TRIGGER `playerdata`.`trg_update_actionQueue_after_playerHiscoreDataXPChange_delete` -AFTER DELETE ON `playerdata`.`playerHiscoreDataXPChange` -FOR EACH ROW -BEGIN - UPDATE actionQueue - SET - processed = TRUE, - end_time = CURRENT_TIMESTAMP - WHERE 1=1 - AND target_table = 'playerHiscoreDataXPChange' - AND action_type = 'DELETE' - AND target_id = OLD.id; -END$$ - - -DELIMITER ; - -SET SQL_MODE=@OLD_SQL_MODE; -SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; -SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/Dockerfile b/mysql/Dockerfile similarity index 100% rename from Dockerfile rename to mysql/Dockerfile diff --git a/docker-entrypoint-initdb.d/000_create_playerdata.sql b/mysql/docker-entrypoint-initdb.d/000_create_playerdata.sql similarity index 100% rename from docker-entrypoint-initdb.d/000_create_playerdata.sql rename to mysql/docker-entrypoint-initdb.d/000_create_playerdata.sql diff --git a/docker-entrypoint-initdb.d/001_create_users.sql b/mysql/docker-entrypoint-initdb.d/001_create_users.sql similarity index 100% rename from docker-entrypoint-initdb.d/001_create_users.sql rename to mysql/docker-entrypoint-initdb.d/001_create_users.sql diff --git a/mysql/docker-entrypoint-initdb.d/002_create_schema.sql b/mysql/docker-entrypoint-initdb.d/002_create_schema.sql new file mode 100644 index 0000000..fd133b8 --- /dev/null +++ b/mysql/docker-entrypoint-initdb.d/002_create_schema.sql @@ -0,0 +1,483 @@ +USE playerdata; + +CREATE TABLE Players ( + id INT PRIMARY KEY AUTO_INCREMENT, + name TEXT, + created_at TIMESTAMP, + updated_at TIMESTAMP, + possible_ban BOOLEAN, + confirmed_ban BOOLEAN, + confirmed_player BOOLEAN, + label_id INTEGER, + label_jagex INTEGER, + ironman BOOLEAN, + hardcore_ironman BOOLEAN, + ultimate_ironman BOOLEAN, + normalized_name TEXT +); + +CREATE TABLE Reports ( + ID BIGINT PRIMARY KEY AUTO_INCREMENT, + created_at TIMESTAMP, + reportedID INT, + reportingID INT, + region_id INT, + x_coord INT, + y_coord INT, + z_coord INT, + timestamp TIMESTAMP, + manual_detect SMALLINT, + on_members_world INT, + on_pvp_world SMALLINT, + world_number INT, + equip_head_id INT, + equip_amulet_id INT, + equip_torso_id INT, + equip_legs_id INT, + equip_boots_id INT, + equip_cape_id INT, + equip_hands_id INT, + equip_weapon_id INT, + equip_shield_id INT, + equip_ge_value BIGINT, + CONSTRAINT FK_Reported_Players_id FOREIGN KEY (reportedID) REFERENCES Players (id) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT FK_Reporting_Players_id FOREIGN KEY (reportingID) REFERENCES Players (id) ON DELETE RESTRICT ON UPDATE RESTRICT +); + + +CREATE TABLE Predictions ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(12), + prediction VARCHAR(50), + created TIMESTAMP, + predicted_confidence DECIMAL(5, 2), + real_player DECIMAL(5, 2) DEFAULT 0, + pvm_melee_bot DECIMAL(5, 2) DEFAULT 0, + smithing_bot DECIMAL(5, 2) DEFAULT 0, + magic_bot DECIMAL(5, 2) DEFAULT 0, + fishing_bot DECIMAL(5, 2) DEFAULT 0, + mining_bot DECIMAL(5, 2) DEFAULT 0, + crafting_bot DECIMAL(5, 2) DEFAULT 0, + pvm_ranged_magic_bot DECIMAL(5, 2) DEFAULT 0, + pvm_ranged_bot DECIMAL(5, 2) DEFAULT 0, + hunter_bot DECIMAL(5, 2) DEFAULT 0, + fletching_bot DECIMAL(5, 2) DEFAULT 0, + clue_scroll_bot DECIMAL(5, 2) DEFAULT 0, + lms_bot DECIMAL(5, 2) DEFAULT 0, + agility_bot DECIMAL(5, 2) DEFAULT 0, + wintertodt_bot DECIMAL(5, 2) DEFAULT 0, + runecrafting_bot DECIMAL(5, 2) DEFAULT 0, + zalcano_bot DECIMAL(5, 2) DEFAULT 0, + woodcutting_bot DECIMAL(5, 2) DEFAULT 0, + thieving_bot DECIMAL(5, 2) DEFAULT 0, + soul_wars_bot DECIMAL(5, 2) DEFAULT 0, + cooking_bot DECIMAL(5, 2) DEFAULT 0, + vorkath_bot DECIMAL(5, 2) DEFAULT 0, + barrows_bot DECIMAL(5, 2) DEFAULT 0, + herblore_bot DECIMAL(5, 2) DEFAULT 0, + unknown_bot DECIMAL(5, 2) DEFAULT 0 +); + +CREATE TABLE playerHiscoreData ( + id bigint NOT NULL AUTO_INCREMENT, + timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + ts_date date DEFAULT NULL, + Player_id int NOT NULL, + total bigint DEFAULT '0', + attack int DEFAULT '0', + defence int DEFAULT '0', + strength int DEFAULT '0', + hitpoints int DEFAULT '0', + ranged int DEFAULT '0', + prayer int DEFAULT '0', + magic int DEFAULT '0', + cooking int DEFAULT '0', + woodcutting int DEFAULT '0', + fletching int DEFAULT '0', + fishing int DEFAULT '0', + firemaking int DEFAULT '0', + crafting int DEFAULT '0', + smithing int DEFAULT '0', + mining int DEFAULT '0', + herblore int DEFAULT '0', + agility int DEFAULT '0', + thieving int DEFAULT '0', + slayer int DEFAULT '0', + farming int DEFAULT '0', + runecraft int DEFAULT '0', + hunter int DEFAULT '0', + construction int DEFAULT '0', + league int DEFAULT '0', + bounty_hunter_hunter int DEFAULT '0', + bounty_hunter_rogue int DEFAULT '0', + cs_all int DEFAULT '0', + cs_beginner int DEFAULT '0', + cs_easy int DEFAULT '0', + cs_medium int DEFAULT '0', + cs_hard int DEFAULT '0', + cs_elite int DEFAULT '0', + cs_master int DEFAULT '0', + lms_rank int DEFAULT '0', + soul_wars_zeal int DEFAULT '0', + abyssal_sire int DEFAULT '0', + alchemical_hydra int DEFAULT '0', + barrows_chests int DEFAULT '0', + bryophyta int DEFAULT '0', + callisto int DEFAULT '0', + cerberus int DEFAULT '0', + chambers_of_xeric int DEFAULT '0', + chambers_of_xeric_challenge_mode int DEFAULT '0', + chaos_elemental int DEFAULT '0', + chaos_fanatic int DEFAULT '0', + commander_zilyana int DEFAULT '0', + corporeal_beast int DEFAULT '0', + crazy_archaeologist int DEFAULT '0', + dagannoth_prime int DEFAULT '0', + dagannoth_rex int DEFAULT '0', + dagannoth_supreme int DEFAULT '0', + deranged_archaeologist int DEFAULT '0', + general_graardor int DEFAULT '0', + giant_mole int DEFAULT '0', + grotesque_guardians int DEFAULT '0', + hespori int DEFAULT '0', + kalphite_queen int DEFAULT '0', + king_black_dragon int DEFAULT '0', + kraken int DEFAULT '0', + kreearra int DEFAULT '0', + kril_tsutsaroth int DEFAULT '0', + mimic int DEFAULT '0', + nex int DEFAULT '0', + nightmare int DEFAULT '0', + phosanis_nightmare int DEFAULT '0', + obor int DEFAULT '0', + phantom_muspah int DEFAULT '0', + sarachnis int DEFAULT '0', + scorpia int DEFAULT '0', + skotizo int DEFAULT '0', + tempoross int DEFAULT '0', + the_gauntlet int DEFAULT '0', + the_corrupted_gauntlet int DEFAULT '0', + theatre_of_blood int DEFAULT '0', + theatre_of_blood_hard int DEFAULT '0', + thermonuclear_smoke_devil int DEFAULT '0', + tombs_of_amascut int DEFAULT '0', + tombs_of_amascut_expert int DEFAULT '0', + tzkal_zuk int DEFAULT '0', + tztok_jad int DEFAULT '0', + venenatis int DEFAULT '0', + vetion int DEFAULT '0', + vorkath int DEFAULT '0', + wintertodt int DEFAULT '0', + zalcano int DEFAULT '0', + zulrah int DEFAULT '0', + rifts_closed int DEFAULT '0', + artio int DEFAULT '0', + calvarion int DEFAULT '0', + duke_sucellus int DEFAULT '0', + spindel int DEFAULT '0', + the_leviathan int DEFAULT '0', + the_whisperer int DEFAULT '0', + vardorvis int DEFAULT '0', + PRIMARY KEY (id), + UNIQUE KEY idx_playerHiscoreData_Player_id_timestamp (Player_id,timestamp), + UNIQUE KEY Unique_player_date (Player_id,ts_date), + CONSTRAINT FK_Players_id FOREIGN KEY (Player_id) REFERENCES Players (id) ON DELETE RESTRICT ON UPDATE RESTRICT +); + +CREATE TABLE playerHiscoreDataLatest ( + id bigint NOT NULL AUTO_INCREMENT, + timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + ts_date date DEFAULT NULL, + Player_id int NOT NULL, + total bigint DEFAULT NULL, + attack int DEFAULT NULL, + defence int DEFAULT NULL, + strength int DEFAULT NULL, + hitpoints int DEFAULT NULL, + ranged int DEFAULT NULL, + prayer int DEFAULT NULL, + magic int DEFAULT NULL, + cooking int DEFAULT NULL, + woodcutting int DEFAULT NULL, + fletching int DEFAULT NULL, + fishing int DEFAULT NULL, + firemaking int DEFAULT NULL, + crafting int DEFAULT NULL, + smithing int DEFAULT NULL, + mining int DEFAULT NULL, + herblore int DEFAULT NULL, + agility int DEFAULT NULL, + thieving int DEFAULT NULL, + slayer int DEFAULT NULL, + farming int DEFAULT NULL, + runecraft int DEFAULT NULL, + hunter int DEFAULT NULL, + construction int DEFAULT NULL, + league int DEFAULT NULL, + bounty_hunter_hunter int DEFAULT NULL, + bounty_hunter_rogue int DEFAULT NULL, + cs_all int DEFAULT NULL, + cs_beginner int DEFAULT NULL, + cs_easy int DEFAULT NULL, + cs_medium int DEFAULT NULL, + cs_hard int DEFAULT NULL, + cs_elite int DEFAULT NULL, + cs_master int DEFAULT NULL, + lms_rank int DEFAULT NULL, + soul_wars_zeal int DEFAULT NULL, + abyssal_sire int DEFAULT NULL, + alchemical_hydra int DEFAULT NULL, + barrows_chests int DEFAULT NULL, + bryophyta int DEFAULT NULL, + callisto int DEFAULT NULL, + cerberus int DEFAULT NULL, + chambers_of_xeric int DEFAULT NULL, + chambers_of_xeric_challenge_mode int DEFAULT NULL, + chaos_elemental int DEFAULT NULL, + chaos_fanatic int DEFAULT NULL, + commander_zilyana int DEFAULT NULL, + corporeal_beast int DEFAULT NULL, + crazy_archaeologist int DEFAULT NULL, + dagannoth_prime int DEFAULT NULL, + dagannoth_rex int DEFAULT NULL, + dagannoth_supreme int DEFAULT NULL, + deranged_archaeologist int DEFAULT NULL, + general_graardor int DEFAULT NULL, + giant_mole int DEFAULT NULL, + grotesque_guardians int DEFAULT NULL, + hespori int DEFAULT NULL, + kalphite_queen int DEFAULT NULL, + king_black_dragon int DEFAULT NULL, + kraken int DEFAULT NULL, + kreearra int DEFAULT NULL, + kril_tsutsaroth int DEFAULT NULL, + mimic int DEFAULT NULL, + nex int DEFAULT NULL, + nightmare int DEFAULT NULL, + phosanis_nightmare int DEFAULT NULL, + obor int DEFAULT NULL, + phantom_muspah int DEFAULT NULL, + sarachnis int DEFAULT NULL, + scorpia int DEFAULT NULL, + skotizo int DEFAULT NULL, + Tempoross int DEFAULT NULL, + the_gauntlet int DEFAULT NULL, + the_corrupted_gauntlet int DEFAULT NULL, + theatre_of_blood int DEFAULT NULL, + theatre_of_blood_hard int DEFAULT NULL, + thermonuclear_smoke_devil int DEFAULT NULL, + tombs_of_amascut int DEFAULT NULL, + tombs_of_amascut_expert int DEFAULT NULL, + tzkal_zuk int DEFAULT NULL, + tztok_jad int DEFAULT NULL, + venenatis int DEFAULT NULL, + vetion int DEFAULT NULL, + vorkath int DEFAULT NULL, + wintertodt int DEFAULT NULL, + zalcano int DEFAULT NULL, + zulrah int DEFAULT NULL, + rifts_closed int DEFAULT '0', + artio int DEFAULT '0', + calvarion int DEFAULT '0', + duke_sucellus int DEFAULT '0', + spindel int DEFAULT '0', + the_leviathan int DEFAULT '0', + the_whisperer int DEFAULT '0', + vardorvis int DEFAULT '0', + PRIMARY KEY (id), + UNIQUE KEY Unique_player (Player_id) USING BTREE, + UNIQUE KEY idx_playerHiscoreDataLatest_Player_id_timestamp (Player_id,timestamp), + UNIQUE KEY idx_playerHiscoreDataLatest_Player_id_ts_date (Player_id,ts_date), + CONSTRAINT FK_latest_player FOREIGN KEY (Player_id) REFERENCES Players (id) ON DELETE RESTRICT ON UPDATE RESTRICT +); +CREATE TABLE playerHiscoreDataXPChange ( + id bigint NOT NULL AUTO_INCREMENT, + timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + ts_date date DEFAULT NULL, + Player_id int NOT NULL, + total bigint DEFAULT NULL, + attack int DEFAULT NULL, + defence int DEFAULT NULL, + strength int DEFAULT NULL, + hitpoints int DEFAULT NULL, + ranged int DEFAULT NULL, + prayer int DEFAULT NULL, + magic int DEFAULT NULL, + cooking int DEFAULT NULL, + woodcutting int DEFAULT NULL, + fletching int DEFAULT NULL, + fishing int DEFAULT NULL, + firemaking int DEFAULT NULL, + crafting int DEFAULT NULL, + smithing int DEFAULT NULL, + mining int DEFAULT NULL, + herblore int DEFAULT NULL, + agility int DEFAULT NULL, + thieving int DEFAULT NULL, + slayer int DEFAULT NULL, + farming int DEFAULT NULL, + runecraft int DEFAULT NULL, + hunter int DEFAULT NULL, + construction int DEFAULT NULL, + league int DEFAULT NULL, + bounty_hunter_hunter int DEFAULT NULL, + bounty_hunter_rogue int DEFAULT NULL, + cs_all int DEFAULT NULL, + cs_beginner int DEFAULT NULL, + cs_easy int DEFAULT NULL, + cs_medium int DEFAULT NULL, + cs_hard int DEFAULT NULL, + cs_elite int DEFAULT NULL, + cs_master int DEFAULT NULL, + lms_rank int DEFAULT NULL, + soul_wars_zeal int DEFAULT NULL, + abyssal_sire int DEFAULT NULL, + alchemical_hydra int DEFAULT NULL, + barrows_chests int DEFAULT NULL, + bryophyta int DEFAULT NULL, + callisto int DEFAULT NULL, + cerberus int DEFAULT NULL, + chambers_of_xeric int DEFAULT NULL, + chambers_of_xeric_challenge_mode int DEFAULT NULL, + chaos_elemental int DEFAULT NULL, + chaos_fanatic int DEFAULT NULL, + commander_zilyana int DEFAULT NULL, + corporeal_beast int DEFAULT NULL, + crazy_archaeologist int DEFAULT NULL, + dagannoth_prime int DEFAULT NULL, + dagannoth_rex int DEFAULT NULL, + dagannoth_supreme int DEFAULT NULL, + deranged_archaeologist int DEFAULT NULL, + general_graardor int DEFAULT NULL, + giant_mole int DEFAULT NULL, + grotesque_guardians int DEFAULT NULL, + hespori int DEFAULT NULL, + kalphite_queen int DEFAULT NULL, + king_black_dragon int DEFAULT NULL, + kraken int DEFAULT NULL, + kreearra int DEFAULT NULL, + kril_tsutsaroth int DEFAULT NULL, + mimic int DEFAULT NULL, + nex int DEFAULT NULL, + nightmare int DEFAULT NULL, + obor int DEFAULT NULL, + phantom_muspah int DEFAULT NULL, + phosanis_nightmare int DEFAULT NULL, + sarachnis int DEFAULT NULL, + scorpia int DEFAULT NULL, + skotizo int DEFAULT NULL, + Tempoross int DEFAULT NULL, + the_gauntlet int DEFAULT NULL, + the_corrupted_gauntlet int DEFAULT NULL, + theatre_of_blood int DEFAULT NULL, + theatre_of_blood_hard int DEFAULT NULL, + thermonuclear_smoke_devil int DEFAULT NULL, + tzkal_zuk int DEFAULT NULL, + tztok_jad int DEFAULT NULL, + venenatis int DEFAULT NULL, + vetion int DEFAULT NULL, + vorkath int DEFAULT NULL, + wintertodt int DEFAULT NULL, + zalcano int DEFAULT NULL, + zulrah int DEFAULT NULL, + rifts_closed int DEFAULT '0', + artio int DEFAULT '0', + calvarion int DEFAULT '0', + duke_sucellus int DEFAULT '0', + spindel int DEFAULT '0', + the_leviathan int DEFAULT '0', + the_whisperer int DEFAULT '0', + vardorvis int DEFAULT '0', + PRIMARY KEY (id), + KEY IDX_xpChange_Player_id_timestamp (Player_id,timestamp) USING BTREE, + KEY IDX_xpChange_Player_id_ts_date (Player_id,ts_date) USING BTREE, + CONSTRAINT fk_phd_xp_pl FOREIGN KEY (Player_id) REFERENCES Players (id) ON DELETE RESTRICT ON UPDATE RESTRICT +); + +CREATE TABLE `scraper_data` ( + `scraper_id` bigint unsigned NOT NULL AUTO_INCREMENT, + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `player_id` int unsigned NOT NULL, + `record_date` date GENERATED ALWAYS AS (cast(`created_at` as date)) STORED, + PRIMARY KEY (`scraper_id`), + UNIQUE KEY `unique_player_per_day` (`player_id`,`record_date`) +); + +CREATE TABLE `scraper_data_latest` ( + `scraper_id` bigint unsigned NOT NULL AUTO_INCREMENT, + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `record_date` date GENERATED ALWAYS AS (cast(`created_at` as date)) STORED, + `player_id` int unsigned NOT NULL, + PRIMARY KEY (`player_id`), + KEY `idx_scraper_id` (`scraper_id`), + KEY `idx_record_date` (`record_date`) +); + + + +CREATE TABLE skills ( + skill_id TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, # < 255 + skill_name VARCHAR(50) NOT NULL, + UNIQUE KEY unique_skill_name (skill_name) +); +CREATE TABLE activities ( + activity_id TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, # < 255 + activity_name VARCHAR(50) NOT NULL, + UNIQUE KEY unique_activity_name (activity_name) +); + + +CREATE TABLE player_skills ( + scraper_id BIGINT UNSIGNED NOT NULL, + skill_id TINYINT UNSIGNED NOT NULL, + skill_value INT UNSIGNED NOT NULL DEFAULT 0, # < 200 000 000 + FOREIGN KEY (scraper_id) REFERENCES scraper_data(scraper_id) ON DELETE CASCADE, + FOREIGN KEY (skill_id) REFERENCES skills(skill_id) ON DELETE CASCADE, + PRIMARY KEY (scraper_id, skill_id) +); + +CREATE TABLE player_activities ( + scraper_id BIGINT UNSIGNED NOT NULL, + activity_id TINYINT UNSIGNED NOT NULL, + activity_value INT UNSIGNED NOT NULL DEFAULT 0, # some guy could get over 65k kc + FOREIGN KEY (scraper_id) REFERENCES scraper_data(scraper_id) ON DELETE CASCADE, + FOREIGN KEY (activity_id) REFERENCES activities(activity_id) ON DELETE CASCADE, + PRIMARY KEY (scraper_id, activity_id) +); + + +DELIMITER // + +CREATE TRIGGER `sd_latest` AFTER INSERT ON `scraper_data` FOR EACH ROW +BEGIN + DECLARE latest_created_at DATETIME; + + -- Get the latest created_at from scraper_data_latest for the current player_id + SELECT created_at INTO latest_created_at + FROM scraper_data_latest + WHERE player_id = NEW.player_id; + + IF latest_created_at IS NULL THEN + INSERT INTO scraper_data_latest (scraper_id, created_at, player_id) + VALUES (NEW.scraper_id, NEW.created_at, NEW.player_id) + ON DUPLICATE KEY UPDATE + scraper_id = NEW.scraper_id, + created_at = NEW.created_at; + ELSEIF NEW.created_at > latest_created_at THEN + UPDATE scraper_data_latest + SET + scraper_id = NEW.scraper_id, + created_at = NEW.created_at + WHERE player_id = NEW.player_id; + END IF; +END // + +DELIMITER ; + +CREATE TABLE `Labels` ( + `id` int NOT NULL AUTO_INCREMENT, + `label` varchar(50) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `Unique_label` (`label`) USING BTREE +) +; \ No newline at end of file diff --git a/mysql/docker-entrypoint-initdb.d/003_create_data.sql b/mysql/docker-entrypoint-initdb.d/003_create_data.sql new file mode 100644 index 0000000..93dbf20 --- /dev/null +++ b/mysql/docker-entrypoint-initdb.d/003_create_data.sql @@ -0,0 +1,151 @@ +USE playerdata; + +INSERT INTO skills (skill_id, skill_name) +VALUES + (2, 'attack'), + (3, 'defence'), + (4, 'strength'), + (5, 'hitpoints'), + (6, 'ranged'), + (7, 'prayer'), + (8, 'magic'), + (9, 'cooking'), + (10, 'woodcutting'), + (11, 'fletching'), + (12, 'fishing'), + (13, 'firemaking'), + (14, 'crafting'), + (15, 'smithing'), + (16, 'mining'), + (17, 'herblore'), + (18, 'agility'), + (19, 'thieving'), + (20, 'slayer'), + (21, 'farming'), + (22, 'runecraft'), + (23, 'hunter'), + (24, 'construction'); + +INSERT INTO activities (activity_id, activity_name) +VALUES + (1, 'abyssal_sire'), + (2, 'alchemical_hydra'), + (3, 'artio'), + (4, 'barrows_chests'), + (5, 'bounty_hunter_hunter'), + (6, 'bounty_hunter_rogue'), + (7, 'bryophyta'), + (8, 'callisto'), + (9, 'calvarion'), + (10, 'cerberus'), + (11, 'chambers_of_xeric'), + ( + 12, 'chambers_of_xeric_challenge_mode' + ), + (13, 'chaos_elemental'), + (14, 'chaos_fanatic'), + (15, 'commander_zilyana'), + (16, 'corporeal_beast'), + (17, 'crazy_archaeologist'), + (18, 'cs_all'), + (19, 'cs_beginner'), + (20, 'cs_easy'), + (21, 'cs_elite'), + (22, 'cs_hard'), + (23, 'cs_master'), + (24, 'cs_medium'), + (25, 'dagannoth_prime'), + (26, 'dagannoth_rex'), + (27, 'dagannoth_supreme'), + (28, 'deranged_archaeologist'), + (29, 'duke_sucellus'), + (30, 'general_graardor'), + (31, 'giant_mole'), + (32, 'grotesque_guardians'), + (33, 'hespori'), + (34, 'kalphite_queen'), + (35, 'king_black_dragon'), + (36, 'kraken'), + (37, 'kreearra'), + (38, 'kril_tsutsaroth'), + (39, 'league'), + (40, 'lms_rank'), + (41, 'mimic'), + (42, 'nex'), + (43, 'nightmare'), + (44, 'obor'), + (45, 'phantom_muspah'), + (46, 'phosanis_nightmare'), + (47, 'rifts_closed'), + (48, 'sarachnis'), + (49, 'scorpia'), + (50, 'skotizo'), + (51, 'soul_wars_zeal'), + (52, 'spindel'), + (53, 'tempoross'), + (54, 'the_corrupted_gauntlet'), + (55, 'the_gauntlet'), + (56, 'the_leviathan'), + (57, 'the_whisperer'), + (58, 'theatre_of_blood'), + (59, 'theatre_of_blood_hard'), + ( + 60, 'thermonuclear_smoke_devil' + ), + (61, 'tombs_of_amascut'), + (62, 'tombs_of_amascut_expert'), + (63, 'tzkal_zuk'), + (64, 'tztok_jad'), + (65, 'vardorvis'), + (66, 'venenatis'), + (67, 'vetion'), + (68, 'vorkath'), + (69, 'wintertodt'), + (70, 'zalcano'), + (71, 'zulrah'); + +INSERT INTO Labels (id, label) +VALUES + (1, 'Real_Player'), + (4, 'Wintertodt_bot'), + (5, 'Mining_bot'), + (7, 'Hunter_bot'), + (8, 'Herblore_bot'), + (9, 'Fletching_bot'), + (10, 'Fishing_bot'), + (11, 'Crafting_bot'), + (12, 'Cooking_bot'), + (13, 'Woodcutting_bot'), + (15, 'Smithing_bot'), + (17, 'Magic_bot'), + (19, 'PVM_Ranged_Magic_bot'), + (21, 'Agility_bot'), + (27, 'Zalcano_bot'), + (38, 'Runecrafting_bot'), + (40, 'PVM_Ranged_bot'), + (41, 'PVM_Melee_bot'), + (42, 'Thieving_bot'), + (52, 'LMS_bot'), + (56, 'Fishing_Cooking_bot'), + (57, 'mort_myre_fungus_bot'), + (59, 'temp_real_player'), + (61, 'Soul_Wars_bot'), + (64, 'Construction_Magic_bot'), + (65, 'Vorkath_bot'), + (66, 'Clue_Scroll_bot'), + (67, 'Barrows_bot'), + (76, 'Woodcutting_Mining_bot'), + ( + 77, 'Woodcutting_Firemaking_bot' + ), + (84, 'Mage_Guild_Store_bot'), + (87, 'Phosani_bot'), + (89, 'Unknown_bot'), + (90, 'Blast_mine_bot'), + (91, 'Zulrah_bot'), + (92, 'test_label'), + (109, 'Nex_bot'), + (110, 'Gauntlet_bot'); + +INSERT INTO Labels (label) VALUES ("Unkown"); +UPDATE Labels set id=0 where label="Unkown"; \ No newline at end of file diff --git a/mysql_setup/Dockerfile b/mysql_setup/Dockerfile new file mode 100644 index 0000000..014cd75 --- /dev/null +++ b/mysql_setup/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.11-slim + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python", "setup_mysql.py"] diff --git a/mysql_setup/models.py b/mysql_setup/models.py new file mode 100644 index 0000000..09fe8ac --- /dev/null +++ b/mysql_setup/models.py @@ -0,0 +1,135 @@ +# script to insert all the data we need +from datetime import datetime + +from sqlalchemy import ( + TIMESTAMP, + BigInteger, + Boolean, + Column, + Date, + DateTime, + ForeignKey, + Integer, + SmallInteger, + String, + func, +) +from sqlalchemy.dialects.mysql import BIGINT, SMALLINT, TINYINT +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() + +class Players(Base): + __tablename__ = "Players" + + id = Column(Integer, primary_key=True) + name = Column(String) + created_at = Column(DateTime, default=datetime.utcnow) + updated_at = Column(DateTime, default=datetime.utcnow) + possible_ban = Column(Boolean, default=True) + confirmed_ban = Column(Boolean, default=False) + confirmed_player = Column(Boolean, default=False) + label_id = Column(Integer) + label_jagex = Column(Integer) + # ironman = Column(Boolean) + # hardcore_ironman = Column(Boolean) + # ultimate_ironman = Column(Boolean) + normalized_name = Column(String) + + +class ScraperData(Base): + __tablename__ = "scraper_data" + + scraper_id = Column(BIGINT, primary_key=True, autoincrement=True) + created_at = Column(DateTime, nullable=False, server_default=func.now()) + player_id = Column(SMALLINT, nullable=False) + record_date = Column(Date, nullable=True, server_default=func.current_date()) + + +class ScraperDataLatest(Base): + __tablename__ = "scraper_data_latest" + + scraper_id = Column(BIGINT) + created_at = Column(DateTime, nullable=False, server_default=func.now()) + player_id = Column(BIGINT, primary_key=True) + record_date = Column(Date, nullable=True, server_default=func.current_date()) + + +class Skills(Base): + __tablename__ = "skills" + + skill_id = Column(TINYINT, primary_key=True, autoincrement=True) + skill_name = Column(String(50), nullable=False) + + +class PlayerSkills(Base): + __tablename__ = "player_skills" + + scraper_id = Column( + BIGINT, + ForeignKey("scraper_data.scraper_id", ondelete="CASCADE"), + primary_key=True, + ) + skill_id = Column( + TINYINT, + ForeignKey("skills.skill_id", ondelete="CASCADE"), + primary_key=True, + ) + skill_value = Column(Integer, nullable=False, default=0) + + +class Activities(Base): + __tablename__ = "activities" + + activity_id = Column(TINYINT, primary_key=True, autoincrement=True) + activity_name = Column(String(50), nullable=False) + + +class PlayerActivities(Base): + __tablename__ = "player_activities" + + scraper_id = Column( + BIGINT, + ForeignKey("scraper_data.scraper_id", ondelete="CASCADE"), + primary_key=True, + ) + activity_id = Column( + TINYINT, + ForeignKey("activities.activity_id", ondelete="CASCADE"), + primary_key=True, + ) + activity_value = Column(Integer, nullable=False, default=0) + + +class Report(Base): + __tablename__ = "Reports" + + ID = Column(BigInteger, primary_key=True, autoincrement=True) + created_at = Column(TIMESTAMP) + reportedID = Column(Integer) + reportingID = Column(Integer) + region_id = Column(Integer) + x_coord = Column(Integer) + y_coord = Column(Integer) + z_coord = Column(Integer) + timestamp = Column(TIMESTAMP) + manual_detect = Column(SmallInteger) + on_members_world = Column(Integer) + on_pvp_world = Column(SmallInteger) + world_number = Column(Integer) + equip_head_id = Column(Integer) + equip_amulet_id = Column(Integer) + equip_torso_id = Column(Integer) + equip_legs_id = Column(Integer) + equip_boots_id = Column(Integer) + equip_cape_id = Column(Integer) + equip_hands_id = Column(Integer) + equip_weapon_id = Column(Integer) + equip_shield_id = Column(Integer) + equip_ge_value = Column(BigInteger) + +class Labels(Base): + __tablename__ = "Labels" + + id = Column(Integer, primary_key=True) + label = Column(String) \ No newline at end of file diff --git a/mysql_setup/requirements.txt b/mysql_setup/requirements.txt new file mode 100644 index 0000000..1ab8080 --- /dev/null +++ b/mysql_setup/requirements.txt @@ -0,0 +1,8 @@ +aiomysql==0.2.0 +cffi==1.16.0 +cryptography==42.0.5 +greenlet==3.0.3 +pycparser==2.22 +PyMySQL==1.1.0 +SQLAlchemy==2.0.28 +typing_extensions==4.10.0 diff --git a/mysql_setup/setup_mysql.py b/mysql_setup/setup_mysql.py new file mode 100644 index 0000000..0b69727 --- /dev/null +++ b/mysql_setup/setup_mysql.py @@ -0,0 +1,186 @@ +# script to insert all the data we need +import random +from datetime import datetime, timedelta + +from sqlalchemy import ( + create_engine, +) +from sqlalchemy.exc import IntegrityError +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker +from models import ( + Players, + Skills, + Activities, + PlayerActivities, + PlayerSkills, + Report, + ScraperData, + Labels, +) + +Base = declarative_base() +random.seed(42) + +# Define other SQLAlchemy models for remaining tables in a similar manner + +# Create an engine and bind the base +engine = create_engine("mysql+pymysql://root:root_bot_buster@mysql:3306/playerdata") +Base.metadata.create_all(engine) + +# Create a session +Session = sessionmaker(bind=engine) +session = Session() + + +# Define function to generate random date within a year +def random_date(): + return datetime.utcnow() - timedelta(days=random.randint(0, 365)) + + +def get_labels(): + # Query the labels table to get all id values + label_ids = session.query(Labels.id).all() + label_ids = [id[0] for id in label_ids] # Convert list of tuples to list of ids + return label_ids + + +def insert_players(len_players, label_ids: list): + # Insert data into Players table + for i in range(len_players): + print(f"Player_{i}") + # Check if the player already exists + existing_player = session.query(Players).filter_by(name=f"Player_{i}").first() + if not existing_player: + player = Players( + name=f"Player_{i}", + created_at=random_date(), + updated_at=random_date(), + possible_ban=random.choice([True, False]), + confirmed_ban=random.choice([True, False]), + confirmed_player=random.choice([True, False]), + label_id=random.choice(label_ids), # Select a random id from label_ids + label_jagex=random.randint(0, 2), + normalized_name=f"Player_{i}", + ) + session.add(player) + session.commit() + return + + +def get_skills(): + # Query the skills table to get all id values + skill_ids = session.query(Skills.skill_id).all() + skill_ids = [id[0] for id in skill_ids] # Convert list of tuples to list of ids + return skill_ids + + +def get_activities(): + # Query the activity table to get all id values + activity_ids = session.query(Activities.activity_id).all() + activity_ids = [ + id[0] for id in activity_ids + ] # Convert list of tuples to list of ids + return activity_ids + + +def insert_scraper_data(len_scraper_data, len_players, skill_ids, activity_ids): + for i in range(1, len_scraper_data + 1): + print(f"scraper_data_{i}") + # pick random player + player_id = random.randint(1, len_players) + + # pick random amount of skills + amount_skills = random.randint(0, len(skill_ids)) + random.shuffle(skill_ids) + skills = skill_ids[:amount_skills] + + # pick random amount of activities + amount_activities = random.randint(0, len(activity_ids)) + random.shuffle(activity_ids) + activities = activity_ids[:amount_activities] + + # scraper data + try: + session.add( + ScraperData(scraper_id=i, player_id=player_id, created_at=random_date()) + ) + session.commit() + for skill in skills: + session.add( + PlayerSkills( + scraper_id=i, + skill_id=skill, + skill_value=random.randint(1, 200_000_000), + ) + ) + for activity in activities: + session.add( + PlayerActivities( + scraper_id=i, + activity_id=activity, + activity_value=random.randint(1, 65_000), + ) + ) + except IntegrityError: + session.rollback() # Rollback the transaction if a duplicate entry is encountered + finally: + session.commit() + + +def insert_reports(len_reports, len_players): + for i in range(1, len_reports + 1): + print(f"Report_{i}") + # pick random player + reporter = random.randint(1, len_players) + reported = random.randint(1, len_players) + + if reporter == reported: + reported = random.randint(1, len_players) + + try: + session.add( + Report( + created_at=random_date(), + reportedID=reporter, + reportingID=reported, + region_id=random.randint(1, 30000), + x_coord=random.randint(1, 30000), + y_coord=random.randint(1, 30000), + z_coord=random.randint(1, 30000), + timestamp=random_date(), + manual_detect=random.choice([0, 1]), + on_members_world=random.choice([0, 1]), + on_pvp_world=random.choice([0, 1]), + world_number=random.randint(1, 300), + equip_head_id=random.randint(1, 30000), + equip_amulet_id=random.randint(1, 30000), + equip_torso_id=random.randint(1, 30000), + equip_legs_id=random.randint(1, 30000), + equip_boots_id=random.randint(1, 30000), + equip_cape_id=random.randint(1, 30000), + equip_hands_id=random.randint(1, 30000), + equip_weapon_id=random.randint(1, 30000), + equip_shield_id=random.randint(1, 30000), + equip_ge_value=random.randint(1, 2000000000), + ) + ) + except IntegrityError: + session.rollback() # Rollback the transaction if a duplicate entry is encountered + finally: + session.commit() + + +def main(): + len_players = 250 + label_ids = get_labels() + insert_players(len_players, label_ids) + skill_ids = get_skills() + activity_ids = get_activities() + len_scraper_data = len_players * 3 + insert_scraper_data(len_scraper_data, len_players, skill_ids, activity_ids) + insert_reports(len_reports=10000, len_players=len_players) + + +if __name__ == "__main__": + main()