user-svc/build.rs

28 lines
837 B
Rust
Raw Normal View History

extern crate dotenv;
use std::{env, collections::HashMap};
use sqlx::Connection;
use dotenv::dotenv;
#[tokio::main]
async fn main(){
2022-07-14 04:52:27 +00:00
println!("cargo:rerun-if-changed=migrations");
dotenv().ok();
let mut dotenv_vars: HashMap<String, String> = HashMap::new();
for (key, val) in env::vars() {
dotenv_vars.insert(key, val);
}
let db_url = match dotenv_vars.get("DATABASE_URL") {
Some(var) => {var},
2022-07-14 04:52:27 +00:00
None => {panic!("DATABASE_URL env var not found, set it!")}
};
let mut conn = match sqlx::MySqlConnection::connect(&db_url).await {
Ok(res) => {res},
Err(e) => {panic!("{}", e)}
};
match sqlx::migrate!("./migrations").run(&mut conn).await {
Ok(()) => {println!("{}", "Successfully ran migrations.")},
Err(error) => {panic!("{error}")}
};
}