Skip to content

Commit

Permalink
Merge pull request #173 from kate-goldenring/rename-database-module
Browse files Browse the repository at this point in the history
chore(links): rename database module to resource
  • Loading branch information
kate-goldenring committed Jan 22, 2024
2 parents 72ffeab + 67bbf03 commit 067260b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
28 changes: 14 additions & 14 deletions src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -305,9 +305,9 @@ impl DeployCommand {
Ok(())
}

fn interaction_strategy(&self) -> anyhow::Result<Box<dyn database::InteractionStrategy>> {
fn interaction_strategy(&self) -> anyhow::Result<Box<dyn resource::InteractionStrategy>> {
if self.links.is_empty() {
return Ok(Box::new(database::Interactive));
return Ok(Box::new(resource::Interactive));
}

let script = parse_linkage_specs(&self.links)?;
Expand Down Expand Up @@ -975,9 +975,9 @@ pub fn config_file_path(deployment_env_id: Option<&str>) -> Result<PathBuf> {
Ok(path)
}

fn parse_linkage_specs(links: &[impl AsRef<str>]) -> anyhow::Result<database::Scripted> {
fn parse_linkage_specs(links: &[impl AsRef<str>]) -> anyhow::Result<resource::Scripted> {
// 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::<LinkageSpec>()) {
let link = link?;
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 0 additions & 7 deletions src/commands/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down

0 comments on commit 067260b

Please sign in to comment.