From a2a597d3d8e65c5299218395d695cf99323ca834 Mon Sep 17 00:00:00 2001 From: quexeky Date: Thu, 4 Sep 2025 12:16:37 +1000 Subject: [PATCH] fix: Fix native_model from requirements and add version requirements for models Signed-off-by: quexeky --- src-tauri/src/database/db.rs | 4 +-- src-tauri/src/database/models.rs | 48 +++++++++++++++----------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src-tauri/src/database/db.rs b/src-tauri/src/database/db.rs index bc08f7a..a6d358e 100644 --- a/src-tauri/src/database/db.rs +++ b/src-tauri/src/database/db.rs @@ -28,7 +28,7 @@ impl DeSerializer for DropDatabaseSerializer { fn serialize(&self, val: &T) -> rustbreak::error::DeSerResult> { - native_model::rmp_serde_1_3::RmpSerde::encode(val) + native_model::encode(val) .map_err(|e| DeSerError::Internal(e.to_string())) } @@ -36,7 +36,7 @@ impl DeSerializer let mut buf = Vec::new(); s.read_to_end(&mut buf) .map_err(|e| rustbreak::error::DeSerError::Other(e.into()))?; - let val = native_model::rmp_serde_1_3::RmpSerde::decode(buf) + let (val, _version) = native_model::decode(buf) .map_err(|e| DeSerError::Internal(e.to_string()))?; Ok(val) } diff --git a/src-tauri/src/database/models.rs b/src-tauri/src/database/models.rs index a2997b2..5fe7a5d 100644 --- a/src-tauri/src/database/models.rs +++ b/src-tauri/src/database/models.rs @@ -1,10 +1,5 @@ -/** - * NEXT BREAKING CHANGE - * - * UPDATE DATABASE TO USE RPMSERDENAMED - * - * WE CAN'T DELETE ANY FIELDS - */ + + pub mod data { use std::path::PathBuf; @@ -12,6 +7,9 @@ pub mod data { use native_model::native_model; use serde::{Deserialize, Serialize}; + // NOTE: Within each version, you should NEVER use these types. + // Declare it using the actual version that it is from, i.e. v1::Settings rather than just Settings from here + pub type GameVersion = v1::GameVersion; pub type Database = v3::Database; pub type Settings = v1::Settings; @@ -180,16 +178,15 @@ pub mod data { use serde_with::serde_as; use super::{ - ApplicationTransientStatus, DatabaseAuth, Deserialize, DownloadableMetadata, - GameVersion, Serialize, Settings, native_model, v1, + Deserialize, Serialize, native_model, v1, }; - #[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde)] + #[native_model(id = 1, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::Database)] #[derive(Serialize, Deserialize, Clone, Default)] pub struct Database { #[serde(default)] - pub settings: Settings, - pub auth: Option, + pub settings: v1::Settings, + pub auth: Option, pub base_url: String, pub applications: v1::DatabaseApplications, #[serde(skip)] @@ -198,7 +195,7 @@ pub mod data { pub compat_info: Option, } - #[native_model(id = 8, version = 2, with = native_model::rmp_serde_1_3::RmpSerde)] + #[native_model(id = 9, version = 1, with = native_model::rmp_serde_1_3::RmpSerde)] #[derive(Serialize, Deserialize, Clone, Default)] pub struct DatabaseCompatInfo { @@ -221,7 +218,7 @@ pub mod data { // Strings are version names for a particular game #[derive(Serialize, Clone, Deserialize, Debug)] #[serde(tag = "type")] - #[native_model(id = 5, version = 2, with = native_model::rmp_serde_1_3::RmpSerde)] + #[native_model(id = 5, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from = v1::GameDownloadStatus)] pub enum GameDownloadStatus { Remote {}, SetupRequired { @@ -261,17 +258,17 @@ pub mod data { #[serde_as] #[derive(Serialize, Clone, Deserialize, Default)] #[serde(rename_all = "camelCase")] - #[native_model(id = 3, version = 2, with = native_model::rmp_serde_1_3::RmpSerde)] + #[native_model(id = 3, version = 2, with = native_model::rmp_serde_1_3::RmpSerde, from=v1::DatabaseApplications)] pub struct DatabaseApplications { pub install_dirs: Vec, // Guaranteed to exist if the game also exists in the app state map pub game_statuses: HashMap, - pub game_versions: HashMap>, - pub installed_game_version: HashMap, + pub game_versions: HashMap>, + pub installed_game_version: HashMap, #[serde(skip)] - pub transient_statuses: HashMap, + pub transient_statuses: HashMap, } impl From for DatabaseApplications { fn from(value: v1::DatabaseApplications) -> Self { @@ -293,21 +290,21 @@ pub mod data { use std::path::PathBuf; use super::{ - DatabaseApplications, DatabaseAuth, DatabaseCompatInfo, Deserialize, Serialize, - Settings, native_model, v2, + Deserialize, Serialize, + native_model, v2, v1, }; - #[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde)] + #[native_model(id = 1, version = 3, with = native_model::rmp_serde_1_3::RmpSerde, from = v2::Database)] #[derive(Serialize, Deserialize, Clone, Default)] pub struct Database { #[serde(default)] - pub settings: Settings, - pub auth: Option, + pub settings: v1::Settings, + pub auth: Option, pub base_url: String, - pub applications: DatabaseApplications, + pub applications: v2::DatabaseApplications, #[serde(skip)] pub prev_database: Option, pub cache_dir: PathBuf, - pub compat_info: Option, + pub compat_info: Option, } impl From for Database { @@ -347,5 +344,6 @@ pub mod data { compat_info: None, } } + } }