-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a migrate command to migrate the db
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
use std::env; | ||
|
||
use anyhow::anyhow; | ||
use api::{ | ||
configuration::get_configuration, | ||
startup::Application, | ||
telemetry::{get_subscriber, init_subscriber}, | ||
}; | ||
use tracing::info; | ||
use tracing_log::log::error; | ||
|
||
#[actix_web::main] | ||
pub async fn main() -> anyhow::Result<()> { | ||
let subscriber = get_subscriber("api".into(), "info".into(), std::io::stdout); | ||
init_subscriber(subscriber); | ||
let configuration = get_configuration().expect("Failed to read configuration."); | ||
info!("{configuration}"); | ||
let application = Application::build(configuration.clone()).await?; | ||
application.run_until_stopped().await?; | ||
let mut args = env::args(); | ||
|
||
if args.len() == 2 { | ||
let command = args.nth(1).unwrap(); | ||
if command == "migrate" { | ||
Application::migrate_database(configuration).await?; | ||
} else { | ||
let message = "invalid command line arguments"; | ||
error!("{message}"); | ||
return Err(anyhow!(message)); | ||
} | ||
} else if args.len() == 1 { | ||
let application = Application::build(configuration.clone()).await?; | ||
application.run_until_stopped().await?; | ||
} else { | ||
let message = "invalid command line arguments"; | ||
error!("{message}"); | ||
return Err(anyhow!(message)); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters