use rocket::{fairing, Build, Rocket};
use rocket_db_pools::Database;

use super::schema::DollTags;

pub async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
	let db = match DollTags::fetch(&rocket) {
		Some(v) => v,
		None => return Err(rocket),
	};

	match sqlx::migrate!().run(&**db).await {
		Ok(_) => Ok(rocket),
		Err(e) => {
			error!("Failed to update database\n{:?}", e);
			Err(rocket)
		}
	}
}
