mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
Add database migration flag
This commit is contained in:
33
src/main.rs
33
src/main.rs
@@ -23,16 +23,15 @@ mod config;
|
|||||||
struct Args {
|
struct Args {
|
||||||
#[arg(short, long, env)]
|
#[arg(short, long, env)]
|
||||||
config_file: String,
|
config_file: String,
|
||||||
|
#[arg(long, env, help = "Run database migrations (only for sql store)")]
|
||||||
|
migrate: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
async fn get_cal_store(
|
||||||
async fn main() -> Result<()> {
|
migrate: bool,
|
||||||
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
config: &CalendarStoreConfig,
|
||||||
|
) -> Result<Arc<RwLock<dyn CalendarStore>>> {
|
||||||
let args = Args::parse();
|
let cal_store: Arc<RwLock<dyn CalendarStore>> = match &config {
|
||||||
let config: Config = toml::from_str(&fs::read_to_string(&args.config_file)?)?;
|
|
||||||
|
|
||||||
let cal_store: Arc<RwLock<dyn CalendarStore>> = match &config.calendar_store {
|
|
||||||
CalendarStoreConfig::Toml(TomlCalendarStoreConfig { db_path }) => {
|
CalendarStoreConfig::Toml(TomlCalendarStoreConfig { db_path }) => {
|
||||||
Arc::new(RwLock::new(match fs::read_to_string(db_path) {
|
Arc::new(RwLock::new(match fs::read_to_string(db_path) {
|
||||||
Ok(content) => toml::from_str::<TomlCalendarStore>(&content).unwrap(),
|
Ok(content) => toml::from_str::<TomlCalendarStore>(&content).unwrap(),
|
||||||
@@ -46,10 +45,24 @@ async fn main() -> Result<()> {
|
|||||||
.create_if_missing(true),
|
.create_if_missing(true),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
sqlx::migrate!("./migrations").run(&db).await?;
|
if migrate {
|
||||||
Arc::new(RwLock::new(SqliteCalendarStore::new(Arc::new(db))))
|
println!("Running database migrations");
|
||||||
|
sqlx::migrate!("./migrations").run(&db).await?;
|
||||||
|
}
|
||||||
|
Arc::new(RwLock::new(SqliteCalendarStore::new(db)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Ok(cal_store)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
||||||
|
|
||||||
|
let args = Args::parse();
|
||||||
|
let config: Config = toml::from_str(&fs::read_to_string(&args.config_file)?)?;
|
||||||
|
|
||||||
|
let cal_store = get_cal_store(args.migrate, &config.calendar_store).await?;
|
||||||
|
|
||||||
let auth: Arc<AuthProvider> = Arc::new(config.auth.into());
|
let auth: Arc<AuthProvider> = Arc::new(config.auth.into());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user