2022-07-14 01:33:30 +00:00
|
|
|
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");
|
2022-07-14 01:33:30 +00:00
|
|
|
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!")}
|
2022-07-14 01:33:30 +00:00
|
|
|
};
|
|
|
|
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}")}
|
|
|
|
};
|
|
|
|
}
|