From 0e82b6981fb9446c3daaaf593d14976d1287e6b8 Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Wed, 9 Nov 2022 12:09:05 -0700 Subject: [PATCH] Bugfix/0.3.3 migration (#1922) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Change migration to use empty name * chore: Add in the default routes just in case * Fix/remove merge with seed during init (#1917) * fix kiosk * chore: Remove the duplicate loggging information that is making usele… (#1912) chore: Remove the duplicate loggging information that is making useless noise in the system. * fix: Remove the init merge with seed Co-authored-by: Aiden McClelland Co-authored-by: BluJ Co-authored-by: J M <2364004+Blu-J@users.noreply.github.com> --- backend/src/init.rs | 18 ------------------ backend/src/version/v0_3_2.rs | 34 +++++++++++++++++++++++++++++++++- backend/src/version/v0_3_3.rs | 15 ++++++++++----- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/backend/src/init.rs b/backend/src/init.rs index adac8f5f4..d9dde8f50 100644 --- a/backend/src/init.rs +++ b/backend/src/init.rs @@ -203,24 +203,6 @@ pub async fn init(cfg: &RpcContextConfig) -> Result { .lock(&mut handle, LockType::Write) .await?; - let defaults: serde_json::Value = - serde_json::from_str(include_str!("../../frontend/patchdb-ui-seed.json")).map_err(|x| { - Error::new( - eyre!("Deserialization error {:?}", x), - crate::ErrorKind::Deserialization, - ) - })?; - let mut ui = crate::db::DatabaseModel::new() - .ui() - .get(&mut handle, false) - .await? - .clone(); - ui.merge_with(&defaults); - crate::db::DatabaseModel::new() - .ui() - .put(&mut handle, &ui) - .await?; - let receipts = InitReceipts::new(&mut handle).await?; let should_rebuild = tokio::fs::metadata(SYSTEM_REBUILD_PATH).await.is_ok() diff --git a/backend/src/version/v0_3_2.rs b/backend/src/version/v0_3_2.rs index ed0cb37ea..e7aeb43db 100644 --- a/backend/src/version/v0_3_2.rs +++ b/backend/src/version/v0_3_2.rs @@ -2,10 +2,34 @@ use emver::VersionRange; use super::v0_3_0::V0_3_0_COMPAT; use super::*; -use crate::hostname::{generate_id, sync_hostname}; +use crate::{ + config::util::MergeWith, + hostname::{generate_id, sync_hostname}, +}; const V0_3_2: emver::Version = emver::Version::new(0, 3, 2, 0); +lazy_static::lazy_static! { + static ref DEFAULT_UI: serde_json::Value =serde_json::json!({ + "name": null, + "auto-check-updates": true, + "pkg-order": [], + "ack-welcome": "0.3.2", + "marketplace": { + "selected-id": null, + "known-hosts": {} + }, + "dev": {}, + "gaming": { + "snake": { + "high-score": 0 + } + }, + "ack-instructions": {} + }); + +} + #[derive(Clone, Debug)] pub struct Version; #[async_trait] @@ -25,6 +49,14 @@ impl VersionT for Version { crate::hostname::ensure_hostname_is_set(db, &receipts).await?; receipts.id.set(db, generate_id()).await?; + let mut ui = crate::db::DatabaseModel::new() + .ui() + .get(db, false) + .await? + .clone(); + ui.merge_with(&DEFAULT_UI); + crate::db::DatabaseModel::new().ui().put(db, &ui).await?; + sync_hostname(db, &receipts).await?; Ok(()) } diff --git a/backend/src/version/v0_3_3.rs b/backend/src/version/v0_3_3.rs index c89ec8bbd..be1345603 100644 --- a/backend/src/version/v0_3_3.rs +++ b/backend/src/version/v0_3_3.rs @@ -58,13 +58,18 @@ impl VersionT for Version { obj.remove("auto-check-updates"); } let known_hosts = ui["marketplace"]["known-hosts"].take(); + ui["marketplace"]["known-hosts"] = json!({}); if let Value::Object(known_hosts) = known_hosts { for (_id, value) in known_hosts { - if let (Value::String(name), Value::String(url)) = (&value["name"], &value["url"]) { - ui["marketplace"]["known-hosts"][name] = json!(url); + if let Value::String(url) = &value["url"] { + ui["marketplace"]["known-hosts"][url] = json!({}); } } } + + ui["marketplace"]["known-hosts"]["https://registry.start9.com/"] = json!({}); + ui["marketplace"]["known-hosts"]["https://community-registry.start9.com/"] = json!({}); + if let Some(Value::Object(ref mut obj)) = ui.get_mut("marketplace") { obj.remove("selected-id"); } @@ -105,10 +110,10 @@ impl VersionT for Version { let known_hosts = ui["marketplace"]["known-hosts"].take(); ui["marketplace"]["known-hosts"] = json!({}); if let Value::Object(known_hosts) = known_hosts { - for (url, name) in known_hosts { - if let Value::String(name) = name { + for (url, obj) in known_hosts { + if let Value::String(name) = &obj["name"] { let id = uuid::Uuid::new_v4().to_string(); - if Some(&name) == selected_url.as_ref() { + if Some(name) == selected_url.as_ref() { ui["marketplace"]["selected-id"] = Value::String(id.clone()); } ui["marketplace"]["known-hosts"][id.as_str()] = json!({