feat: init recovery CLI tool

This commit is contained in:
EETagent 2022-10-30 10:50:58 +01:00
parent cfb2fb047b
commit 4c8546f81e
3 changed files with 81 additions and 1 deletions

View file

@ -6,7 +6,7 @@ edition = "2021"
publish = false
[workspace]
members = [".", "api", "core", "entity", "migration"]
members = [".", "api", "core", "entity", "migration", "recovery"]
[dependencies]
portfolio-api = { path = "api" }

25
recovery/Cargo.toml Normal file
View file

@ -0,0 +1,25 @@
[package]
name = "portfolio-recovery"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
url = "^2.3"
clap = { version = "^4.0", features = ["cargo"] }
portfolio-entity = { path = "../entity" }
[dependencies.tokio]
version = "^1.21"
features = [
"macros",
]
[dependencies.sea-orm]
version = "^0.10"
features = [
"sqlx-sqlite",
# TODO: Migrate to rustls for better compatibility with various OS
"runtime-tokio-native-tls"
]

55
recovery/src/main.rs Normal file
View file

@ -0,0 +1,55 @@
use std::path::PathBuf;
use url::Url;
use clap::{arg, command, value_parser};
use sea_orm::{Database, DatabaseConnection};
use sea_orm::*;
use ::entity::candidate::Entity as Candidate;
use ::entity::parent::Entity as Parent;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let clap = command!()
.arg(arg!([name] "Path to the db .sql backup"))
.arg(
arg!(
-d --database <DATABASE> "Path to the database SQL backup file"
)
.required(true)
.value_parser(value_parser!(PathBuf)),
)
.arg(
arg!(
-p --portfolio <PATH> "Path to the portfolio root"
)
.required(true)
.value_parser(value_parser!(PathBuf)),
)
.arg(
arg!(
-k --key <KEY> "AGE private key for decryption"
)
.required(true),
)
.get_matches();
let mut sqlite_url = Url::from_file_path(clap.get_one::<PathBuf>("DATABASE").unwrap()).unwrap();
sqlite_url.set_scheme("sqlite").unwrap();
let db: DatabaseConnection = Database::connect(sqlite_url.as_str()).await?;
let entries = Candidate::find()
.join_rev(
JoinType::InnerJoin,
Parent::belongs_to(Candidate)
.from(::entity::parent::Column::Application)
.to(::entity::candidate::Column::Application)
.into(),
)
.all(&db)
.await?;
Ok(())
}