mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-22 20:41:53 +03:00
34 lines
884 B
Rust
34 lines
884 B
Rust
use affine_schema::get_migrator;
|
|
use sqlx::sqlite::SqliteConnectOptions;
|
|
use std::fs;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
napi_build::setup();
|
|
|
|
// always start with a fresh database to have latest db schema
|
|
let cwd = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
let db_path = format!("{cwd}/affine.db");
|
|
|
|
if fs::metadata(&db_path).is_ok() {
|
|
fs::remove_file(&db_path)?;
|
|
}
|
|
|
|
let options = SqliteConnectOptions::new()
|
|
.filename(&db_path)
|
|
.journal_mode(sqlx::sqlite::SqliteJournalMode::Off)
|
|
.locking_mode(sqlx::sqlite::SqliteLockingMode::Exclusive)
|
|
.create_if_missing(true);
|
|
let pool = sqlx::sqlite::SqlitePoolOptions::new()
|
|
.max_connections(1)
|
|
.connect_with(options)
|
|
.await
|
|
.unwrap();
|
|
|
|
get_migrator().run(&pool).await.unwrap();
|
|
|
|
println!("cargo::rustc-env=DATABASE_URL=sqlite://{db_path}");
|
|
|
|
Ok(())
|
|
}
|