diff --git a/.gitignore b/.gitignore index 3ca43ae..650ad72 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb +# This we generate in this project +*.sqlite diff --git a/Cargo.toml b/Cargo.toml index 631d158..8c77a38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,5 +2,5 @@ members = [ "common", - "core", + "store", ] diff --git a/store/Cargo.toml b/store/Cargo.toml index 640e569..23fe845 100644 --- a/store/Cargo.toml +++ b/store/Cargo.toml @@ -2,7 +2,13 @@ name = "store" version = "0.1.0" edition = "2021" +authors = ["Julio Biason ", ] +description = "Memoirs storage server" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.0.29", features = ["env", "derive", "color"] } +dotenv = "0.15.0" +sqlx = { version = "0.6.2", features = ["sqlite", "uuid", "chrono", "migrate", "runtime-tokio-rustls"] } +tokio = { version = "1.22.0", features = ["macros", "rt"] } diff --git a/store/migrations/202212051652_initial.sql b/store/migrations/202212051652_initial.sql new file mode 100644 index 0000000..cbaf107 --- /dev/null +++ b/store/migrations/202212051652_initial.sql @@ -0,0 +1,23 @@ +CREATE TABLE IF NOT EXISTS entry ( + id TEXT PRIMARY KEY, + title TEXT, + content TEXT, + source TEXT +); + +CREATE TABLE IF NOT EXISTS meta ( + id TEXT PRIMARY KEY, + entry TEXT REFERENCES entry (id) + ON DELETE CASCADE, + name VARCHAR(255), + value VARCHAR(255) +); + +CREATE TABLE IF NOT EXISTS attachment ( + id TEXT PRIMARY KEY, + entry TEXT REFERENCES entry (id) + ON DELETE CASCADE, + name VARCHAR(100), + content_type VARCHAR(100), + content TEXT +); diff --git a/store/src/domain/mod.rs b/store/src/domain/mod.rs index fda665a..2812cb7 100644 --- a/store/src/domain/mod.rs +++ b/store/src/domain/mod.rs @@ -1 +1,3 @@ //! Store own domain. + +pub mod options; diff --git a/store/src/domain/options.rs b/store/src/domain/options.rs new file mode 100644 index 0000000..18ef1a8 --- /dev/null +++ b/store/src/domain/options.rs @@ -0,0 +1,15 @@ +//! Options for running the Store server. + +use std::path::PathBuf; + +use clap::Parser; + +#[derive(Parser)] +#[command(author, version, long_about, color = clap::ColorChoice::Always)] +/// Store is the central part of the Memoirs. It keeps all the data from +/// the several Capturers and offers searches for the Viewers. +pub struct Options { + /// Working directory + #[arg(short, long, env = "STORE_PATH", default_value = "./")] + pub working_directory: PathBuf, +} diff --git a/store/src/lib.rs b/store/src/lib.rs deleted file mode 100644 index 6b92c53..0000000 --- a/store/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -mod domain; diff --git a/store/src/main.rs b/store/src/main.rs new file mode 100644 index 0000000..42b3917 --- /dev/null +++ b/store/src/main.rs @@ -0,0 +1,24 @@ +use clap::Parser; +use sqlx::sqlite::SqliteConnectOptions; +use sqlx::sqlite::SqlitePoolOptions; + +use crate::domain::options::Options; + +mod domain; + +#[tokio::main] +async fn main() -> Result<(), sqlx::Error> { + dotenv::dotenv().ok(); + let options = Options::parse(); + + let pool = SqlitePoolOptions::new() + .connect_with( + SqliteConnectOptions::new() + .filename(options.working_directory.join("memoirs.sqlite")) + .create_if_missing(true), + ) + .await?; + sqlx::migrate!("./migrations").run(&pool).await?; + print!("Hello world!"); + Ok(()) +}