Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(links): rename database module to resource #173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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