stats-v1-migration.sql
· 6.0 KiB · MySQL
Raw
rename table stats_games to stats_sessions;
create table stats_games
(
id int unsigned auto_increment primary key,
uuid uuid default uuid() not null comment 'legacy campaignID' unique,
date_start bigint not null comment 'unix timestamp',
date_start_finale int null comment 'unix timestamp of finale',
date_end bigint null comment 'unix timestamp',
duraton_game bigint as (`date_end` - `date_start`) comment 'seconds of game',
duration_finale bigint as (`date_end` - `date_start_finale`) comment 'seconds of finale',
map_id varchar(64) not null comment 'map id of last chapter',
gamemode varchar(64) not null,
difficulty tinyint null,
server_tags varchar(255) not null comment 'comma separated list of tags',
stat_version tinyint unsigned not null comment 'version of metrics',
index stats_games_gamemode_index (gamemode),
index stats_games_map_id_index (map_id)
);
insert into stats_games (uuid, date_start, date_start_finale, date_end, map_id, gamemode, difficulty, server_tags, stat_version)
# add stats_games data from session data
SELECT campaignID, date_start, date_end-finale_time, date_end, map, gamemode, difficulty, server_tags, 0
FROM stats_sessions group by campaignID
order by id asc;
alter table stats_sessions
add game_id int unsigned not null after id,
drop map,
drop gamemode,
drop difficulty,
drop finale_time,
drop server_tags,
drop DamageDealt,
change zombie_kills kills_common int unsigned default 0 not null,
change melee_kills kills_melee smallint(10) unsigned default 0 not null,
change SurvivorDamage damage_dealt int unsigned default 0 not null,
change SurvivorFFCount damage_dealt_friendly_count mediumint unsigned default 0 not null,
change SurvivorFFTakenCount damage_taken_friendly_count int null,
change SurvivorFFDamage damage_dealt_friendly int null,
change SurvivorFFTakenDamage damage_taken_friendly int null,
change MedkitsUsed used_kit_self tinyint(10) unsigned default 0 not null comment 'heal self',
change FirstAidShared used_kit_other tinyint(10) unsigned default 0 not null comment 'healed teammate',
change PillsUsed used_pills smallint(10) unsigned default 0 not null,
change MolotovsUsed used_molotov smallint(10) unsigned default 0 not null,
add times_hanging smallint unsigned default 0 null after times_revive_other,
change PipebombsUsed used_pipebomb smallint(10) unsigned default 0 not null,
change BoomerBilesUsed used_bile smallint(10) unsigned default 0 not null,
change AdrenalinesUsed used_adrenaline smallint(10) unsigned default 0 not null,
change DefibrillatorsUsed used_defib smallint(10) unsigned default 0 not null,
change DamageTaken damage_taken int unsigned default 0 not null,
change ReviveOtherCount times_revive_other smallint(10) unsigned default 0 not null,
change Incaps times_incapped smallint(10) unsigned default 0 not null,
change Deaths deaths tinyint(10) unsigned default 0 not null,
change boomer_kills kills_boomer smallint(10) unsigned not null,
add kills_tank smallint unsigned null after kills_all_specials,
change smoker_kills kills_smoker smallint(10) unsigned not null,
change jockey_kills kills_jockey smallint(10) unsigned not null,
add kills_witch smallint unsigned null after kills_tank,
change hunter_kills kills_hunter smallint(10) unsigned not null,
add kills_fire smallint unsigned null comment 'gasca/molotov' after kills_witch,
add kills_pipebomb smallint unsigned null after kills_fire,
change spitter_kills kills_spitter smallint(10) unsigned not null,
change charger_kills kills_charger smallint(10) unsigned not null,
add kills_minigun smallint unsigned null after kills_pipebomb,
change SpecialInfectedKills kills_all_specials int unsigned as (`kills_boomer` + `kills_smoker` + `kills_jockey` + `kills_hunter` + `kills_spitter` + `kills_charger`),
modify honks smallint unsigned default 0 null comment 'clowns honked',
change WitchesCrowned witches_crowned smallint(8) unsigned default 0 not null,
change SmokersSelfCleared smokers_selfcleared smallint(8) unsigned default 0 not null,
change RocksHitBy rocks_hitby smallint(8) unsigned default 0 not null,
change RocksDodged rocks_dodged smallint(8) unsigned default 0 not null,
change HuntersDeadstopped hunters_deadstopped smallint(8) unsigned default 0 not null,
change TimesPinned times_pinned smallint(8) unsigned default 0 not null,
change ClearedPinned times_cleared_pinned smallint(8) unsigned default 0 null comment 'helped pinned teammate',
change BoomedTeammates times_boomed_teammates smallint unsigned default 0 not null,
change TimesBoomed times_boomed smallint(8) unsigned default 0 not null,
change DamageToTank damage_dealt_tank mediumint unsigned default 0 not null comment 'dmg to tank',
change DamageToWitch damage_dealt_witch mediumint unsigned default 0 not null comment 'dmg to witch',
change CarAlarmsActivated caralarms_activated tinyint unsigned default 0 not null,
add longest_shot_distance float null,
add seconds_alive int unsigned not null,
add seconds_idle int unsigned not null,
add seconds_dead int unsigned default 0,
add seconds_total int unsigned as (seconds_alive + seconds_idle + seconds_dead);
# TODO: game_id to new id
# TODO: minutes_idle, minutes_played to map to seconds_
update stats_sessions u
join stats_games g on g.uuid = u.campaignID
SET u.game_id=g.id, u.seconds_alive=duration*60, u.seconds_idle=u.minutes_idle*60;
alter table stats_sessions
drop duration,
drop date_start,
drop date_end,
drop minutes_idle,
add constraint stats_sessions_stats_games_id_fk
foreign key (game_id)
references stats_games (id)
on update cascade on delete cascade;
select * from stats_games;
select * from stats_sessions;
| 1 | rename table stats_games to stats_sessions; |
| 2 | create table stats_games |
| 3 | ( |
| 4 | id int unsigned auto_increment primary key, |
| 5 | uuid uuid default uuid() not null comment 'legacy campaignID' unique, |
| 6 | date_start bigint not null comment 'unix timestamp', |
| 7 | date_start_finale int null comment 'unix timestamp of finale', |
| 8 | date_end bigint null comment 'unix timestamp', |
| 9 | duraton_game bigint as (`date_end` - `date_start`) comment 'seconds of game', |
| 10 | duration_finale bigint as (`date_end` - `date_start_finale`) comment 'seconds of finale', |
| 11 | map_id varchar(64) not null comment 'map id of last chapter', |
| 12 | gamemode varchar(64) not null, |
| 13 | difficulty tinyint null, |
| 14 | server_tags varchar(255) not null comment 'comma separated list of tags', |
| 15 | stat_version tinyint unsigned not null comment 'version of metrics', |
| 16 | index stats_games_gamemode_index (gamemode), |
| 17 | index stats_games_map_id_index (map_id) |
| 18 | ); |
| 19 | insert into stats_games (uuid, date_start, date_start_finale, date_end, map_id, gamemode, difficulty, server_tags, stat_version) |
| 20 | # add stats_games data from session data |
| 21 | SELECT campaignID, date_start, date_end-finale_time, date_end, map, gamemode, difficulty, server_tags, 0 |
| 22 | FROM stats_sessions group by campaignID |
| 23 | order by id asc; |
| 24 | alter table stats_sessions |
| 25 | add game_id int unsigned not null after id, |
| 26 | drop map, |
| 27 | drop gamemode, |
| 28 | drop difficulty, |
| 29 | drop finale_time, |
| 30 | drop server_tags, |
| 31 | drop DamageDealt, |
| 32 | change zombie_kills kills_common int unsigned default 0 not null, |
| 33 | change melee_kills kills_melee smallint(10) unsigned default 0 not null, |
| 34 | change SurvivorDamage damage_dealt int unsigned default 0 not null, |
| 35 | change SurvivorFFCount damage_dealt_friendly_count mediumint unsigned default 0 not null, |
| 36 | change SurvivorFFTakenCount damage_taken_friendly_count int null, |
| 37 | change SurvivorFFDamage damage_dealt_friendly int null, |
| 38 | change SurvivorFFTakenDamage damage_taken_friendly int null, |
| 39 | change MedkitsUsed used_kit_self tinyint(10) unsigned default 0 not null comment 'heal self', |
| 40 | change FirstAidShared used_kit_other tinyint(10) unsigned default 0 not null comment 'healed teammate', |
| 41 | change PillsUsed used_pills smallint(10) unsigned default 0 not null, |
| 42 | change MolotovsUsed used_molotov smallint(10) unsigned default 0 not null, |
| 43 | add times_hanging smallint unsigned default 0 null after times_revive_other, |
| 44 | change PipebombsUsed used_pipebomb smallint(10) unsigned default 0 not null, |
| 45 | change BoomerBilesUsed used_bile smallint(10) unsigned default 0 not null, |
| 46 | change AdrenalinesUsed used_adrenaline smallint(10) unsigned default 0 not null, |
| 47 | change DefibrillatorsUsed used_defib smallint(10) unsigned default 0 not null, |
| 48 | change DamageTaken damage_taken int unsigned default 0 not null, |
| 49 | change ReviveOtherCount times_revive_other smallint(10) unsigned default 0 not null, |
| 50 | change Incaps times_incapped smallint(10) unsigned default 0 not null, |
| 51 | change Deaths deaths tinyint(10) unsigned default 0 not null, |
| 52 | change boomer_kills kills_boomer smallint(10) unsigned not null, |
| 53 | add kills_tank smallint unsigned null after kills_all_specials, |
| 54 | change smoker_kills kills_smoker smallint(10) unsigned not null, |
| 55 | change jockey_kills kills_jockey smallint(10) unsigned not null, |
| 56 | add kills_witch smallint unsigned null after kills_tank, |
| 57 | change hunter_kills kills_hunter smallint(10) unsigned not null, |
| 58 | add kills_fire smallint unsigned null comment 'gasca/molotov' after kills_witch, |
| 59 | add kills_pipebomb smallint unsigned null after kills_fire, |
| 60 | change spitter_kills kills_spitter smallint(10) unsigned not null, |
| 61 | change charger_kills kills_charger smallint(10) unsigned not null, |
| 62 | add kills_minigun smallint unsigned null after kills_pipebomb, |
| 63 | change SpecialInfectedKills kills_all_specials int unsigned as (`kills_boomer` + `kills_smoker` + `kills_jockey` + `kills_hunter` + `kills_spitter` + `kills_charger`), |
| 64 | modify honks smallint unsigned default 0 null comment 'clowns honked', |
| 65 | change WitchesCrowned witches_crowned smallint(8) unsigned default 0 not null, |
| 66 | change SmokersSelfCleared smokers_selfcleared smallint(8) unsigned default 0 not null, |
| 67 | change RocksHitBy rocks_hitby smallint(8) unsigned default 0 not null, |
| 68 | change RocksDodged rocks_dodged smallint(8) unsigned default 0 not null, |
| 69 | change HuntersDeadstopped hunters_deadstopped smallint(8) unsigned default 0 not null, |
| 70 | change TimesPinned times_pinned smallint(8) unsigned default 0 not null, |
| 71 | change ClearedPinned times_cleared_pinned smallint(8) unsigned default 0 null comment 'helped pinned teammate', |
| 72 | change BoomedTeammates times_boomed_teammates smallint unsigned default 0 not null, |
| 73 | change TimesBoomed times_boomed smallint(8) unsigned default 0 not null, |
| 74 | change DamageToTank damage_dealt_tank mediumint unsigned default 0 not null comment 'dmg to tank', |
| 75 | change DamageToWitch damage_dealt_witch mediumint unsigned default 0 not null comment 'dmg to witch', |
| 76 | change CarAlarmsActivated caralarms_activated tinyint unsigned default 0 not null, |
| 77 | add longest_shot_distance float null, |
| 78 | add seconds_alive int unsigned not null, |
| 79 | add seconds_idle int unsigned not null, |
| 80 | add seconds_dead int unsigned default 0, |
| 81 | add seconds_total int unsigned as (seconds_alive + seconds_idle + seconds_dead); |
| 82 | |
| 83 | # TODO: game_id to new id |
| 84 | # TODO: minutes_idle, minutes_played to map to seconds_ |
| 85 | update stats_sessions u |
| 86 | join stats_games g on g.uuid = u.campaignID |
| 87 | SET u.game_id=g.id, u.seconds_alive=duration*60, u.seconds_idle=u.minutes_idle*60; |
| 88 | alter table stats_sessions |
| 89 | drop duration, |
| 90 | drop date_start, |
| 91 | drop date_end, |
| 92 | drop minutes_idle, |
| 93 | add constraint stats_sessions_stats_games_id_fk |
| 94 | foreign key (game_id) |
| 95 | references stats_games (id) |
| 96 | on update cascade on delete cascade; |
| 97 | select * from stats_games; |
| 98 | select * from stats_sessions; |
| 99 |