Fixes to database path when using --data opt

This commit is contained in:
Joe Bellus 2022-02-14 22:22:07 -05:00
parent b1c8342253
commit e8fae5d2d2
4 changed files with 12 additions and 9 deletions

View File

@ -30,7 +30,7 @@ tokio = { version = "1.16.1", features=["full"] }
base64 = "0.13.0"
sqlx = { version = "^0.5", features=["sqlite", "migrate"] }
reqwest = { version = "0.11.9", features = ["rustls-tls"], default-features=false }
clap = { version = "3.0.14", features=["cargo", "env"] }
clap = { version = "^3.0", features=["cargo", "env"] }
[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator]

View File

@ -3,4 +3,4 @@ COPY target/x86_64-unknown-linux-musl/release/vade /app/vade
EXPOSE 8089
WORKDIR app
RUN mkdir data
CMD ["./vade", "--db data/"]
CMD ./vade --data data/

View File

@ -2,7 +2,7 @@ use std::{collections::HashMap, path::Path};
use actix::SystemService;
use actix_web::{get, web, App, HttpResponse, HttpServer};
use clap::crate_version;
use clap::rate_version;
use rust_embed::RustEmbed;
use sea_orm::{prelude::*, Database};
use tokio::sync::Mutex;
@ -29,7 +29,7 @@ pub struct AppState {
#[actix_rt::main]
async fn main() {
let opts = clap::App::new("Vade Mecum")
.version(crate_version!())
.version(rate_version!())
.arg(
clap::Arg::new("port")
.short('p')
@ -172,13 +172,15 @@ async fn dist(path: web::Path<String>) -> HttpResponse {
#[instrument]
async fn setup_database(db_path: &str) -> error::Result<DatabaseConnection> {
let db_fname = "data.db";
if !Path::new(db_path).join(db_fname).exists() {
std::fs::File::create(db_fname)?;
let full_path = Path::new(db_path).join(db_fname);
println!("path: {:?}", full_path);
if !full_path.exists() {
std::fs::File::create(full_path.clone())?;
}
let pool = sqlx::SqlitePool::connect("sqlite://data.db").await?;
let conn = format!("sqlite://{}", full_path.to_str().unwrap());
let pool = sqlx::SqlitePool::connect(&conn).await?;
sqlx::migrate!("./migrations").run(&pool).await?;
tracing::info!("Database migrated");
Ok(Database::connect("sqlite://data.db").await?)
Ok(Database::connect(&conn).await?)
}

View File

@ -59,6 +59,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for EventSession {
}
}
#[tracing::instrument(skip(req, stream, state))]
pub async fn event_session_index(
req: HttpRequest,
stream: web::Payload,