mirror of
https://codeberg.org/icewind/log-normalizer.git
synced 2026-06-03 13:54:11 +02:00
handle if all are upgraded
This commit is contained in:
parent
9b7d5d29f3
commit
e4af32f6d4
3 changed files with 36 additions and 34 deletions
|
|
@ -12,9 +12,10 @@ CREATE TYPE event_type AS ENUM ('charge', 'pointcap', 'medic_death', 'round_win'
|
|||
|
||||
CREATE TYPE medigun AS ENUM ('medigun', 'kritzkrieg', 'quickfix', 'vaccinator');
|
||||
|
||||
CREATE FUNCTION clean_map_name(map TEXT) RETURNS TEXT AS $$
|
||||
SELECT regexp_replace(map, '((_(a|b|beta|u|r|v|rc|final|comptf|ugc|nb)?[0-9]*){1,2}[a-z]?$)|([0-9]+[a-z]?$)', '', 'g');
|
||||
$$ LANGUAGE SQL IMMUTABLE;
|
||||
CREATE OR REPLACE FUNCTION clean_map_name(map TEXT)
|
||||
RETURNS TEXT AS $$
|
||||
SELECT regexp_replace(replace(map, 'workshop/', ''), '((_(a|b|beta|u|r|v|rc|final|comptf|ugc|f)?[0-9]*[a-z]?)?(_(a|b|beta|u|r|v|rc|final|comptf|ugc|f)?[0-9]*[a-z]?(_nb[0-9]*)?)|([0-9]+[a-z]?))(\.[a-z0-9]+)?$', '', 'g');
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
CREATE TABLE logs (
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
|
|
|||
|
|
@ -25,26 +25,6 @@
|
|||
"nullable": []
|
||||
}
|
||||
},
|
||||
"094070119b4aeddc0bc17bfd96d96a23a31b08a425569ea95f9c9f32cb1d02aa": {
|
||||
"query": "SELECT MIN(id) as id from logs WHERE version < $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int2"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
}
|
||||
},
|
||||
"253ca64f81921ad7351335d8b47967a4b6831b16d8128a11b40daa63b31f5a4c": {
|
||||
"query": "INSERT INTO players (log_id, steam_id, name, team, kills, deaths, assists,suicides, dmg, damage_taken, ubers, medigun_ubers,kritzkrieg_ubers, quickfix_ubers, vaccinator_ubers,drops, medkits, medkits_hp, backstabs, headshots,heal, heals_received,scout_kills, soldier_kills, pyro_kills, demoman_kills,heavy_kills, engineer_kills, medic_kills, sniper_kills, spy_kills,\n scout_deaths, soldier_deaths, pyro_deaths, demoman_deaths,heavy_deaths, engineer_deaths, medic_deaths, sniper_deaths, spy_deaths\n )VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,$11, $12, $13, $14, $15, $16, $17, $18, $19, $20,$21, $22, $23, $24, $25, $26, $27, $28, $29, $30,$31, $32, $33, $34, $35, $36, $37, $38, $39, $40)RETURNING id",
|
||||
"describe": {
|
||||
|
|
@ -115,6 +95,26 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"25a688892917d80b8746d77ebbcdfb4652c7047d722c530b4560d6008cdd2b97": {
|
||||
"query": "SELECT MIN(id) as \"id\" from logs WHERE version < $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int2"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
}
|
||||
},
|
||||
"417cfaecb2cb45d16c9da2dc2f8e6d1a37280842a5fc9ffb85b5d1955a54670d": {
|
||||
"query": "INSERT INTO logs(id, red_score, blue_score, length, game_mode, map, type, date, version)VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
"describe": {
|
||||
|
|
|
|||
11
src/main.rs
11
src/main.rs
|
|
@ -40,6 +40,7 @@ async fn normalize(database_url: &str, raw_database_url: &str) -> Result<(), Mai
|
|||
let old = get_min_old_stored_log(&pool, VERSION).await?;
|
||||
let from = get_max_stored_log(&pool).await?;
|
||||
|
||||
if let Some(old) = old {
|
||||
for id in old..=from {
|
||||
info!(id = id, from = OLD_VERSION, to = VERSION, "migrating");
|
||||
if let Some(log) = get_log(&raw_pool, id).await? {
|
||||
|
|
@ -48,6 +49,7 @@ async fn normalize(database_url: &str, raw_database_url: &str) -> Result<(), Mai
|
|||
error!(id = id, "invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for id in (from + 1)..=max {
|
||||
if let Some(log) = get_log(&raw_pool, id).await? {
|
||||
|
|
@ -61,15 +63,14 @@ async fn normalize(database_url: &str, raw_database_url: &str) -> Result<(), Mai
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_min_old_stored_log(pool: &PgPool, version: i16) -> Result<i32, MainError> {
|
||||
async fn get_min_old_stored_log(pool: &PgPool, version: i16) -> Result<Option<i32>, MainError> {
|
||||
Ok(sqlx::query!(
|
||||
r#"SELECT MIN(id) as id from logs WHERE version < $1"#,
|
||||
r#"SELECT MIN(id) as "id" from logs WHERE version < $1"#,
|
||||
version
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.fetch_optional(pool)
|
||||
.await?
|
||||
.id
|
||||
.unwrap_or_default())
|
||||
.and_then(|row| row.id))
|
||||
}
|
||||
|
||||
async fn get_max_stored_log(pool: &PgPool) -> Result<i32, MainError> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue