hyper_scripter_historian/migration/
mod.rs

1use sqlx::migrate::MigrateError;
2use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
3use std::path::Path;
4
5pub async fn do_migrate(
6    file: impl AsRef<Path> + std::fmt::Debug,
7) -> Result<SqlitePool, MigrateError> {
8    log::info!("進行資料庫遷移 {:?}!", file);
9    let pool = SqlitePool::connect_with(
10        SqliteConnectOptions::new()
11            .filename(file)
12            .create_if_missing(true),
13    )
14    .await?;
15
16    sqlx::migrate!("./migrations").run(&pool).await?;
17    Ok(pool)
18}