diff --git a/readme.gymhistory.md b/readme.gymhistory.md index 56ed4b38..b198d419 100644 --- a/readme.gymhistory.md +++ b/readme.gymhistory.md @@ -1,9 +1,7 @@ -Use the following SQL-Statements to create the new table: -========================================================= +## Use the following SQL-Statements to create the new table: --- --- Table structure for table `gymhistory` --- +### Table structure for table `gymhistory` +```sql CREATE TABLE IF NOT EXISTS `gymhistory` ( `id` int(11) NOT NULL AUTO_INCREMENT, `gym_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, @@ -22,24 +20,22 @@ CREATE TABLE IF NOT EXISTS `gymhistory` ( KEY `last_updated` (`last_updated`), KEY `combined` (`gym_id`, `team_id`, `total_cp`, `last_updated`, `pokemon_count`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +``` --- --- Add inital dataset for table `gymhistory` --- +### Add inital dataset for table `gymhistory` +```sql INSERT INTO `gymhistory` ( SELECT NULL, g.gym_id, g.team_id, g.guard_pokemon_id, g.total_cp, g.last_modified, g.last_modified as last_updated, (SELECT GROUP_CONCAT(DISTINCT pokemon_uid ORDER BY deployment_time SEPARATOR ',') FROM gymmember AS gm WHERE gm.gym_id = g.gym_id GROUP BY gym_id) AS pokemon_uids, (SELECT COUNT(DISTINCT pokemon_uid) FROM gymmember AS gm WHERE gm.gym_id = g.gym_id) AS pokemon_count FROM gym AS g ); +``` +## Use the following SQL-Statements to create the event to update the new table: -Use the following SQL-Statements to create the event to update the new table: -============================================================================= - --- --- Create event `gymhistory_update` --- +### Create event `gymhistory_update` +```sql DELIMITER // CREATE EVENT IF NOT EXISTS `gymhistory_update` ON SCHEDULE EVERY 15 SECOND @@ -55,8 +51,9 @@ DO BEGIN END // DELIMITER ; +``` --- --- Enable MySQL event scheduler --- -SET GLOBAL event_scheduler = ON; \ No newline at end of file +### Enable MySQL event scheduler +```sql +SET GLOBAL event_scheduler = ON; +```