diff --git a/tembo-cli/src/cli/tembo_config.rs b/tembo-cli/src/cli/tembo_config.rs index 7358e8705..799d3074d 100644 --- a/tembo-cli/src/cli/tembo_config.rs +++ b/tembo-cli/src/cli/tembo_config.rs @@ -103,9 +103,14 @@ fn default_extensions() -> Option> { Some(HashMap::new()) } +fn default_as_true() -> bool { + true +} + #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct Extension { pub version: Option, + #[serde(default = "default_as_true")] pub enabled: bool, pub trunk_project: Option, pub trunk_project_version: Option, diff --git a/tembo-cli/src/cmd/apply.rs b/tembo-cli/src/cmd/apply.rs index 96ab53788..34bf82f39 100644 --- a/tembo-cli/src/cmd/apply.rs +++ b/tembo-cli/src/cmd/apply.rs @@ -612,6 +612,7 @@ fn create_new_instance( env: Environment, ) -> Result { let maybe_instance = get_create_instance(value); + println!("{:?}", maybe_instance); match maybe_instance { Ok(instance) => { @@ -893,10 +894,14 @@ fn get_extensions( name); let ext_locations = extension_mismatch.unwrap().locations.clone(); if !ext_locations.is_empty() { - if let Some(existing_version) = ext_locations[0].clone().version { - version = existing_version + if ext_locations[0].clone().error.unwrap() == Some(false) { + if let Some(existing_version) = ext_locations[0].clone().version { + version = existing_version + } else { + return Err(Error::msg(version_error)); + } } else { - return Err(Error::msg(version_error)); + return Err(Error::msg("Error adding Extension to your instance.")); } } else { return Err(Error::msg(version_error)); @@ -909,7 +914,7 @@ fn get_extensions( vec![ExtensionInstallLocation { database: Some("postgres".to_string()), schema: None, - version: Some(version), + version: version, enabled: extension.enabled, }]; @@ -956,11 +961,18 @@ fn get_trunk_installs( let mut vec_trunk_installs: Vec = vec![]; if let Some(extensions) = maybe_extensions { - for (_, extension) in extensions.into_iter() { + for (name, extension) in extensions.into_iter() { + let version = Runtime::new() + .unwrap() + .block_on(get_extension_version( + name.clone(), + extension.clone().version, + )) + .expect("msg"); if extension.trunk_project.is_some() { vec_trunk_installs.push(TrunkInstall { name: extension.trunk_project.unwrap(), - version: Some(extension.trunk_project_version), + version: version, }); } } @@ -1300,7 +1312,6 @@ async fn get_extension_version( if let Some(version) = maybe_version { return Ok(Some(version)); } - let trunk_projects = get_trunk_projects(&name).await?; // If trunk projects returned is not exactly 1 then skip getting version diff --git a/tembo-cli/temboclient/src/models/create_instance.rs b/tembo-cli/temboclient/src/models/create_instance.rs index add1b5a8e..ce880cd55 100644 --- a/tembo-cli/temboclient/src/models/create_instance.rs +++ b/tembo-cli/temboclient/src/models/create_instance.rs @@ -31,7 +31,6 @@ pub struct CreateInstance { #[serde( rename = "extensions", default, - with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none" )] pub extensions: Option>>, diff --git a/tembo-cli/temboclient/src/models/extension_install_location.rs b/tembo-cli/temboclient/src/models/extension_install_location.rs index fd0fd3362..4ff25d82a 100644 --- a/tembo-cli/temboclient/src/models/extension_install_location.rs +++ b/tembo-cli/temboclient/src/models/extension_install_location.rs @@ -27,13 +27,8 @@ pub struct ExtensionInstallLocation { )] pub schema: Option>, /// The extension version to install. If not specified, the latest version will be used. - #[serde( - rename = "version", - default, - with = "::serde_with::rust::double_option", - skip_serializing_if = "Option::is_none" - )] - pub version: Option>, + #[serde(rename = "version", default, skip_serializing_if = "Option::is_none")] + pub version: Option, } impl ExtensionInstallLocation { diff --git a/tembo-cli/temboclient/src/models/trunk_install.rs b/tembo-cli/temboclient/src/models/trunk_install.rs index 16458fda9..27dfa7e49 100644 --- a/tembo-cli/temboclient/src/models/trunk_install.rs +++ b/tembo-cli/temboclient/src/models/trunk_install.rs @@ -16,13 +16,8 @@ pub struct TrunkInstall { #[serde(rename = "name")] pub name: String, /// The version of the extension to install. If not specified, the latest version will be used. (Optional) - #[serde( - rename = "version", - default, - with = "::serde_with::rust::double_option", - skip_serializing_if = "Option::is_none" - )] - pub version: Option>, + #[serde(rename = "version", default, skip_serializing_if = "Option::is_none")] + pub version: Option, } impl TrunkInstall {