From 67bbf03f1e5431cee7aa1c4b0872c74e609d896f Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Sun, 21 Jan 2024 17:21:33 -0800 Subject: [PATCH] chore(links): rename database module to resource Signed-off-by: Kate Goldenring --- src/commands/deploy.rs | 28 +++++++++---------- .../deploy/{database.rs => resource.rs} | 3 +- src/commands/sqlite.rs | 7 ----- 3 files changed, 16 insertions(+), 22 deletions(-) rename src/commands/deploy/{database.rs => resource.rs} (99%) diff --git a/src/commands/deploy.rs b/src/commands/deploy.rs index 5987b0a..376f5c8 100644 --- a/src/commands/deploy.rs +++ b/src/commands/deploy.rs @@ -34,7 +34,7 @@ use crate::{ opts::*, }; -mod database; +mod resource; const DEVELOPER_CLOUD_FAQ: &str = "https://developer.fermyon.com/cloud/faq"; const SPIN_DEFAULT_KV_STORE: &str = "default"; @@ -207,7 +207,7 @@ impl DeployCommand { // Create or update app let app_id = match client.get_app_id(&name).await? { Some(app_id) => { - database::create_and_link_resources_for_existing_app( + resource::create_and_link_resources_for_existing_app( &client, &name, app_id, @@ -237,7 +237,7 @@ impl DeployCommand { app_id } None => { - let resources_to_link = match database::create_resources_for_new_app( + let resources_to_link = match resource::create_resources_for_new_app( &client, &name, db_labels, @@ -256,7 +256,7 @@ impl DeployCommand { .context("Unable to create app")?; // Now that the app has been created, we can link resources to it. - database::link_resources(&client, &name, app_id, resources_to_link).await?; + resource::link_resources(&client, &name, app_id, resources_to_link).await?; client .add_revision(storage_id.clone(), version.clone()) .await @@ -305,9 +305,9 @@ impl DeployCommand { Ok(()) } - fn interaction_strategy(&self) -> anyhow::Result> { + fn interaction_strategy(&self) -> anyhow::Result> { if self.links.is_empty() { - return Ok(Box::new(database::Interactive)); + return Ok(Box::new(resource::Interactive)); } let script = parse_linkage_specs(&self.links)?; @@ -975,9 +975,9 @@ pub fn config_file_path(deployment_env_id: Option<&str>) -> Result { Ok(path) } -fn parse_linkage_specs(links: &[impl AsRef]) -> anyhow::Result { +fn parse_linkage_specs(links: &[impl AsRef]) -> anyhow::Result { // TODO: would this be nicer as a fold? - let mut strategy = database::Scripted::default(); + let mut strategy = resource::Scripted::default(); for link in links.iter().map(|s| s.as_ref().parse::()) { let link = link?; @@ -1169,7 +1169,7 @@ mod test { .withf(|db, rlabel| db == "excel" && rlabel.is_none()) .returning(|_, _| Ok(())); - let databases_to_link = database::create_resources_for_new_app( + let databases_to_link = resource::create_resources_for_new_app( &client, "test:script-new-app", db_labels, @@ -1190,7 +1190,7 @@ mod test { .withf(|db, rlabel| db == "excel" && rlabel.label == "finance") .returning(|_, _| Ok(())); - database::link_resources( + resource::link_resources( &client, "test:script-new-app", uuid::Uuid::new_v4(), @@ -1228,7 +1228,7 @@ mod test { .withf(|s, rlabel| s == "excel" && rlabel.is_none()) .returning(|_, _| Ok(())); - let stores_to_link = database::create_resources_for_new_app( + let stores_to_link = resource::create_resources_for_new_app( &client, "test:script-new-app", HashSet::new(), @@ -1249,7 +1249,7 @@ mod test { .withf(|db, rlabel| db == "excel" && rlabel.label == "finance") .returning(|_, _| Ok(())); - database::link_resources( + resource::link_resources( &client, "test:script-new-app", uuid::Uuid::new_v4(), @@ -1298,7 +1298,7 @@ mod test { .withf(|db, rlabel| db == "excel" && rlabel.is_none()) .returning(|_, _| Ok(())); - let stores_to_link = database::create_resources_for_new_app( + let stores_to_link = resource::create_resources_for_new_app( &client, "test:script-new-app", db_labels, @@ -1327,7 +1327,7 @@ mod test { .withf(|db, rlabel| db == "excel" && rlabel.label == "finance") .returning(|_, _| Ok(())); - database::link_resources( + resource::link_resources( &client, "test:script-new-app", uuid::Uuid::new_v4(), diff --git a/src/commands/deploy/database.rs b/src/commands/deploy/resource.rs similarity index 99% rename from src/commands/deploy/database.rs rename to src/commands/deploy/resource.rs index 54c86bc..67d006e 100644 --- a/src/commands/deploy/database.rs +++ b/src/commands/deploy/resource.rs @@ -1,4 +1,5 @@ -// TODO(kate): rename this module to something more generic like `resource` +//! Functions for creating and linking resources (such as key value stores and +//! databases) to apps during application deployment use anyhow::{anyhow, bail, Context, Result}; use cloud::CloudClientInterface; use cloud_openapi::models::ResourceLabel; diff --git a/src/commands/sqlite.rs b/src/commands/sqlite.rs index f0eee1f..1c020df 100644 --- a/src/commands/sqlite.rs +++ b/src/commands/sqlite.rs @@ -297,13 +297,6 @@ impl RenameCommand { } } -pub fn database_has_link(database: &Database, label: &str, app: Option<&str>) -> bool { - database - .links - .iter() - .any(|l| l.label == label && l.app_name.as_deref() == app) -} - #[cfg(test)] mod sqlite_tests { use super::*;