allow specifying path to db on cli
parent
d56601cd61
commit
06d30433e5
|
@ -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);
|
||||
}
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue