mirror of
https://codeberg.org/icewind/log-normalizer.git
synced 2026-06-03 22:04:05 +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
23
src/main.rs
23
src/main.rs
|
|
@ -40,12 +40,14 @@ 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?;
|
||||
|
||||
for id in old..=from {
|
||||
info!(id = id, from = OLD_VERSION, to = VERSION, "migrating");
|
||||
if let Some(log) = get_log(&raw_pool, id).await? {
|
||||
upgrade(&pool, id, &log, OLD_VERSION, VERSION).await?;
|
||||
} else {
|
||||
error!(id = id, "invalid");
|
||||
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? {
|
||||
upgrade(&pool, id, &log, OLD_VERSION, VERSION).await?;
|
||||
} else {
|
||||
error!(id = id, "invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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