From 4ec35c792214d9a4fb683c9c54ff7733c7b9cf54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asger=20Juul=20Brunsh=C3=B8j?= Date: Fri, 28 Mar 2025 14:50:32 +0100 Subject: [PATCH] migrate wall to 11 rows --- crates/ascend/src/pages/wall.rs | 8 ++------ crates/ascend/src/server/migrations.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/crates/ascend/src/pages/wall.rs b/crates/ascend/src/pages/wall.rs index 9ceb128..9df1743 100644 --- a/crates/ascend/src/pages/wall.rs +++ b/crates/ascend/src/pages/wall.rs @@ -356,11 +356,7 @@ fn AttemptRadioGroup() -> impl IntoView { attempt_radio_buttons.push(view! { }); } - view! { -
- {attempt_radio_buttons} -
- } + view! {
{attempt_radio_buttons}
} } #[component] @@ -438,7 +434,7 @@ fn Wall() -> impl IntoView { let style = { let grid_rows = crate::css::grid_rows_n(wall.rows); let grid_cols = crate::css::grid_cols_n(wall.cols); - let max_width = format!("{}vh", wall.rows as f64 / wall.cols as f64 * 100.); + let max_width = format!("{}vh", wall.cols as f64 / wall.rows as f64 * 100.); format!("max-height: 100vh; max-width: {max_width}; {}", [grid_rows, grid_cols].join(" ")) }; diff --git a/crates/ascend/src/server/migrations.rs b/crates/ascend/src/server/migrations.rs index b51a5ce..95da404 100644 --- a/crates/ascend/src/server/migrations.rs +++ b/crates/ascend/src/server/migrations.rs @@ -1,12 +1,38 @@ use super::db::Database; use super::db::DatabaseOperationError; use super::db::{self}; +use crate::models; +use redb::ReadableTable; #[tracing::instrument(skip_all, err)] pub async fn run_migrations(db: &Database) -> Result<(), Box> { if is_at_version(db, 2).await? { migrate_to_v3(db).await?; } + + migrate_wall(db).await?; + + Ok(()) +} + +#[tracing::instrument(skip_all, err)] +pub async fn migrate_wall(db: &Database) -> Result<(), Box> { + tracing::warn!("MIGRATING WALL"); + + db.write(|txn| { + let mut table = txn.open_table(db::current::TABLE_WALLS)?; + let wall = table + .get(models::WallUid(uuid::Uuid::parse_str("8a00ab39-89f5-4fc5-b9c6-f86b4c040f68").unwrap()))? + .map(|x| x.value()); + if let Some(mut wall) = wall { + wall.rows = 11; + wall.holds.retain(|k, v| k.row < 11); + table.insert(wall.uid, wall)?; + } + Ok(()) + }) + .await?; + Ok(()) }