--reinitialize param, logging
parent
7baa91f179
commit
fc7635bf70
|
@ -15,6 +15,7 @@ use crate::addressing::Address;
|
||||||
use crate::hash::{decode, encode, hash, Hash, Hashable};
|
use crate::hash::{decode, encode, hash, Hash, Hashable};
|
||||||
use crate::models;
|
use crate::models;
|
||||||
use serde::export::Formatter;
|
use serde::export::Formatter;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Entry {
|
pub struct Entry {
|
||||||
|
@ -289,7 +290,7 @@ impl Handler<InsertEntry> for DbExecutor {
|
||||||
|
|
||||||
let connection = &self.0.get()?;
|
let connection = &self.0.get()?;
|
||||||
|
|
||||||
debug!("Inserting {:?}...", msg.entry);
|
debug!("Inserting: {}", msg.entry);
|
||||||
|
|
||||||
let insert_entry = models::Entry {
|
let insert_entry = models::Entry {
|
||||||
identity: msg.entry.hash()?.0,
|
identity: msg.entry.hash()?.0,
|
||||||
|
@ -375,10 +376,15 @@ pub struct OpenResult {
|
||||||
pub new: bool,
|
pub new: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_upend<P: AsRef<Path>>(dirpath: P) -> Result<OpenResult> {
|
const DATABASE_FILENAME: &str = "upend.sqlite3";
|
||||||
|
|
||||||
|
pub fn open_upend<P: AsRef<Path>>(dirpath: P, reinitialize: bool) -> Result<OpenResult> {
|
||||||
embed_migrations!("./migrations/upend/");
|
embed_migrations!("./migrations/upend/");
|
||||||
|
|
||||||
let database_path: PathBuf = dirpath.as_ref().join("upend.sqlite3");
|
let database_path: PathBuf = dirpath.as_ref().join(DATABASE_FILENAME);
|
||||||
|
if reinitialize {
|
||||||
|
let _ = fs::remove_file(&database_path);
|
||||||
|
}
|
||||||
let new = !database_path.exists();
|
let new = !database_path.exists();
|
||||||
|
|
||||||
let manager = ConnectionManager::<SqliteConnection>::new(database_path.to_str().unwrap());
|
let manager = ConnectionManager::<SqliteConnection>::new(database_path.to_str().unwrap());
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -3,9 +3,9 @@ extern crate diesel;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel_migrations;
|
extern crate diesel_migrations;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{env, fs};
|
|
||||||
|
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use actix_web::{middleware, App, HttpServer};
|
use actix_web::{middleware, App, HttpServer};
|
||||||
|
@ -41,6 +41,11 @@ fn main() -> std::io::Result<()> {
|
||||||
Arg::with_name("NO_BROWSER")
|
Arg::with_name("NO_BROWSER")
|
||||||
.long("no-browser")
|
.long("no-browser")
|
||||||
.help("Do not open web browser with the UI."),
|
.help("Do not open web browser with the UI."),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("REINITIALIZE")
|
||||||
|
.long("reinitialize")
|
||||||
|
.help("Delete and initialize database, if it exists already."),
|
||||||
);
|
);
|
||||||
|
|
||||||
let matches = app.get_matches();
|
let matches = app.get_matches();
|
||||||
|
@ -50,8 +55,8 @@ fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
let vault_path = PathBuf::from(matches.value_of("DIRECTORY").unwrap());
|
let vault_path = PathBuf::from(matches.value_of("DIRECTORY").unwrap());
|
||||||
|
|
||||||
let _ = fs::remove_file(&vault_path.join("upend.sqlite3")); // TODO REMOVE!!!
|
let open_result = database::open_upend(&vault_path, matches.is_present("REINITIALIZE"))
|
||||||
let open_result = database::open_upend(&vault_path).expect("failed to open database!");
|
.expect("failed to open database!");
|
||||||
|
|
||||||
let pool = open_result.pool;
|
let pool = open_result.pool;
|
||||||
let db_addr = SyncArbiter::start(3, move || database::DbExecutor(pool.clone()));
|
let db_addr = SyncArbiter::start(3, move || database::DbExecutor(pool.clone()));
|
||||||
|
@ -96,7 +101,6 @@ fn main() -> std::io::Result<()> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO REMOVE
|
|
||||||
if !matches.is_present("NO_BROWSER") {
|
if !matches.is_present("NO_BROWSER") {
|
||||||
let ui_result = webbrowser::open(&format!("http://localhost:{}", bind.port()));
|
let ui_result = webbrowser::open(&format!("http://localhost:{}", bind.port()));
|
||||||
if ui_result.is_err() {
|
if ui_result.is_err() {
|
||||||
|
|
Loading…
Reference in New Issue