Running migrations.

This commit is contained in:
Tom Alexander
2022-02-13 22:16:19 -05:00
parent 6e08a0c8c3
commit 111d9026c5
3 changed files with 34 additions and 2 deletions

View File

@@ -1,8 +1,12 @@
use std::{env, fs::FileType};
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::sqlite::SqlitePool;
use std::env;
use std::str::FromStr;
use walkdir::DirEntry;
use walkdir::WalkDir;
fn main() {
#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
let mut args = env::args();
let _program = args.next().expect("argv[0] should be this program?");
let profile = args.next().expect("Must provide a profile");
@@ -22,4 +26,18 @@ fn main() {
for f in files {
println!("{}", f.path().display());
}
let db_path = dirs::home_dir()
.map(|pb| pb.join(".record_watch.sqlite"))
.unwrap();
let url = format!("sqlite://{}", db_path.as_path().display());
println!("{}", &url);
let pool =
SqlitePool::connect_with(SqliteConnectOptions::from_str(&url)?.create_if_missing(true))
.await?;
sqlx::migrate!("./migrations").run(&pool).await?;
Ok(())
}