tenebrous-sheets/src/migrator.rs

22 lines
605 B
Rust
Raw Normal View History

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