Get db_url from Db in run_migrations
This commit is contained in:
parent
a5ea54df61
commit
b825df1331
@ -3,6 +3,7 @@ use rocket::form::{Context, Form};
|
|||||||
use rocket::fs::{relative, FileServer};
|
use rocket::fs::{relative, FileServer};
|
||||||
use rocket::response::{Flash, Redirect};
|
use rocket::response::{Flash, Redirect};
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
|
use rocket::Config;
|
||||||
use rocket::{Build, Request, Rocket};
|
use rocket::{Build, Request, Rocket};
|
||||||
use rocket_db_pools::{sqlx, Connection, Database};
|
use rocket_db_pools::{sqlx, Connection, Database};
|
||||||
use rocket_dyn_templates::{context, Template};
|
use rocket_dyn_templates::{context, Template};
|
||||||
@ -102,13 +103,8 @@ pub fn not_found(req: &Request<'_>) -> Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
|
async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
let db_url = Db::fetch(&rocket).unwrap().db_url.clone();
|
||||||
let db_url = "mysql://root:@localhost/rocket_example";
|
let conn = sea_orm::Database::connect(&db_url).await.unwrap();
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
|
||||||
let db_url = "postgres://root:root@localhost/rocket_example";
|
|
||||||
|
|
||||||
let conn = sea_orm::Database::connect(db_url).await.unwrap();
|
|
||||||
|
|
||||||
let _create_post_table = setup::create_post_table(&conn).await;
|
let _create_post_table = setup::create_post_table(&conn).await;
|
||||||
Ok(rocket)
|
Ok(rocket)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use rocket_db_pools::{rocket::figment::Figment, Config, Error};
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RocketDbPool {
|
pub struct RocketDbPool {
|
||||||
db_url: String,
|
pub db_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user