diff --git a/Cargo.lock b/Cargo.lock index 7a1fa0f..c0fb0b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,6 +48,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -183,6 +194,41 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "digest" version = "0.9.0" @@ -224,6 +270,25 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "env_logger" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "form_urlencoded" version = "1.0.1" @@ -408,6 +473,18 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.2.3" @@ -468,6 +545,9 @@ version = "0.1.0" dependencies = [ "async-trait", "directories", + "env_logger", + "log", + "log-derive", "sqlx", "tokio", ] @@ -507,6 +587,18 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "log-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a42526bb432bcd1b43571d5f163984effa25409a29f1a3242a54d0577d55bcf" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "maplit" version = "1.0.2" @@ -927,6 +1019,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + [[package]] name = "syn" version = "1.0.75" @@ -944,6 +1042,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.26" @@ -1213,6 +1320,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/lib/src/database.rs b/lib/src/database.rs index ba02071..6aad72b 100644 --- a/lib/src/database.rs +++ b/lib/src/database.rs @@ -37,7 +37,9 @@ pub async fn connect_with(filename: &Path) -> Result, sqlx::Error> .create_if_missing(true), ) .await?; + log::debug!("Starting migration..."); sqlx::migrate!("./migrations").run(&pool).await?; + log::debug!("Migration concluded"); Ok(pool) } diff --git a/lib/src/domain/command.rs b/lib/src/domain/command.rs index 00f0143..603e777 100644 --- a/lib/src/domain/command.rs +++ b/lib/src/domain/command.rs @@ -16,6 +16,8 @@ along with this program. If not, see . */ +use std::convert::Infallible; + use async_trait::async_trait; /// Trait/tag for DTOs @@ -40,3 +42,9 @@ impl From for CommandError { Self::DatabaseError } } + +impl From for CommandError { + fn from(_error: Infallible) -> Self { + Self::DatabaseError + } +} diff --git a/lib/src/domain/project/create.rs b/lib/src/domain/project/create.rs index 513e6af..1797482 100644 --- a/lib/src/domain/project/create.rs +++ b/lib/src/domain/project/create.rs @@ -16,6 +16,9 @@ along with this program. If not, see . */ +use std::path::PathBuf; +use std::str::FromStr; + use async_trait::async_trait; use super::dto::Project; @@ -35,7 +38,12 @@ impl Create { #[async_trait] impl Command for Create { async fn execute(&self) -> Result<&Project, CommandError> { - let pool = database::connect().await?; + log::debug!( + "Creating project \"{}\": \"{}\"", + self.0.code(), + self.0.name() + ); + let pool = database::connect_with(PathBuf::from_str("./test.sqlite")?.as_path()).await?; let repo = Repository::new(&pool); repo.save(&self.0).await?; Ok(&self.0) @@ -46,10 +54,11 @@ impl Command for Create { mod tests { use super::*; - #[test] - fn should_create_project() { + #[tokio::test] + async fn should_create_project() { + env_logger::init(); let project = Project::new("project", "some project"); let command = Create::new(project); - assert!(command.execute().is_ok()); + assert!(command.execute().await.is_ok()); } }