allow specifying path to db on cli

feat/vaults
Tomáš Mládek 2021-06-19 12:32:05 +02:00
parent d56601cd61
commit 06d30433e5
2 changed files with 18 additions and 4 deletions

View File

@ -701,10 +701,15 @@ pub struct OpenResult {
pub const DATABASE_FILENAME: &str = "upend.sqlite3";
pub fn open_upend<P: AsRef<Path>>(dirpath: P, reinitialize: bool) -> Result<OpenResult> {
pub fn open_upend<P: AsRef<Path>>(
dirpath: P,
db_path: Option<PathBuf>,
reinitialize: bool,
) -> Result<OpenResult> {
embed_migrations!("./migrations/upend/");
let database_path: PathBuf = dirpath.as_ref().join(DATABASE_FILENAME);
let database_path = db_path.unwrap_or_else(|| dirpath.as_ref().join(DATABASE_FILENAME));
if reinitialize {
let _ = fs::remove_file(&database_path);
}

View File

@ -42,6 +42,11 @@ fn main() -> Result<()> {
.help("address and port to bind the Web interface on")
.required(true),
)
.arg(
Arg::with_name("DB_PATH")
.long("db-path")
.help("path to sqlite db file (\"$VAULT_PATH/upend.sqlite\" by default)"),
)
.arg(
Arg::with_name("NO_BROWSER")
.long("no-browser")
@ -73,8 +78,12 @@ fn main() -> Result<()> {
let vault_path = PathBuf::from(matches.value_of("DIRECTORY").unwrap());
let open_result = database::open_upend(&vault_path, matches.is_present("REINITIALIZE"))
.expect("failed to open database!");
let open_result = database::open_upend(
&vault_path,
matches.value_of("DB_PATH").map(PathBuf::from),
matches.is_present("REINITIALIZE"),
)
.expect("failed to open database!");
let db_pool = open_result.pool;