tenebrous-sheets/src/migrator.rs

23 lines
669 B
Rust

use refinery::config::{Config, ConfigDbType};
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::ConnectOptions;
use std::str::FromStr;
pub mod migrations;
/// Run database migrations against the sqlite database.
pub(crate) async fn migrate(db_path: &str) -> Result<(), Box<dyn std::error::Error>> {
//Create database if missing.
let conn = SqliteConnectOptions::from_str(&format!("sqlite://{}", db_path))?
.create_if_missing(true)
.connect()
.await?;
drop(conn);
let mut conn = Config::new(ConfigDbType::Sqlite).set_db_path(db_path);
println!("Running migrations");
migrations::runner().run(&mut conn)?;
Ok(())
}