Skip to content

Commit

Permalink
Remove default to install extensions in CLI (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajerin authored Jun 21, 2024
1 parent 0e29ac5 commit c130604
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
5 changes: 5 additions & 0 deletions tembo-cli/src/cli/tembo_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ fn default_extensions() -> Option<HashMap<String, Extension>> {
Some(HashMap::new())
}

fn default_as_true() -> bool {
true
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Extension {
pub version: Option<String>,
#[serde(default = "default_as_true")]
pub enabled: bool,
pub trunk_project: Option<String>,
pub trunk_project_version: Option<String>,
Expand Down
25 changes: 18 additions & 7 deletions tembo-cli/src/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ fn create_new_instance(
env: Environment,
) -> Result<String, String> {
let maybe_instance = get_create_instance(value);
println!("{:?}", maybe_instance);

match maybe_instance {
Ok(instance) => {
Expand Down Expand Up @@ -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));
Expand All @@ -909,7 +914,7 @@ fn get_extensions(
vec![ExtensionInstallLocation {
database: Some("postgres".to_string()),
schema: None,
version: Some(version),
version: version,
enabled: extension.enabled,
}];

Expand Down Expand Up @@ -956,11 +961,18 @@ fn get_trunk_installs(
let mut vec_trunk_installs: Vec<TrunkInstall> = 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,
});
}
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tembo-cli/temboclient/src/models/create_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<Vec<crate::models::Extension>>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ pub struct ExtensionInstallLocation {
)]
pub schema: Option<Option<String>>,
/// 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<Option<String>>,
#[serde(rename = "version", default, skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}

impl ExtensionInstallLocation {
Expand Down
9 changes: 2 additions & 7 deletions tembo-cli/temboclient/src/models/trunk_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<String>>,
#[serde(rename = "version", default, skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}

impl TrunkInstall {
Expand Down

0 comments on commit c130604

Please sign in to comment.