10000 database config just work with `default` and `global` · Issue #2936 · rwf2/Rocket · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

database config just work with default and global #2936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
4 tasks done
icode opened this issue Apr 27, 2025 · 0 comments
Open
4 tasks done

database config just work with default and global #2936

icode opened this issue Apr 27, 2025 · 0 comments
Labels
triage A bug report being investigated

Comments

@icode
Copy link
icode commented Apr 27, 2025

Rocket Version

0.5.1

Operating System

macOS 15.4.1

Rust Toolchain Version

rustc 1.86.0 (05f9846f8 2025-03-31)

What happened?

database pool config can not read [debug] config. just support [default],[global].

Test Case

use rocket::fairing::{self, AdHoc};
use rocket::{Build, Rocket};

use rocket_db_pools::{sqlx, Database};

#[derive(Database)]
#[database("postgres")]
struct Db(sqlx::PgPool);

async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
    match Db::fetch(&rocket) {
        Some(db) => match sqlx::migrate!("src/sqlx/migrations").run(&**db).await {
            Ok(_) => Ok(rocket),
            Err(e) => {
                error!("Failed to initialize SQLx database: {}", e);
                Err(rocket)
            }
        },
        None => Err(rocket),
    }
}

pub trait ConfigureDbRocket {
    fn configure_db(self) -> Self;
}

impl ConfigureDbRocket for Rocket<Build> {
    fn configure_db(self) -> Self {
        self.attach(Db::init())
            .attach(AdHoc::try_on_ignite("SQLx Migrations", run_migrations))
    }
}

#[launch]
fn rocket() -> _ {
    rocket::custom(Config::default_figment())
        .attach(AdHoc::config::<rocket::Config>())
        .attach(AdHoc::config::<Config>())
        .configure_db()
}

Log Output

Error: failed to initialize database: bad configuration: missing field `url`
Error: Attempted to fetch unattached database `moke::sqlx::Db`.
   >> `moke::sqlx::Db::init()` fairing must be attached prior to using this database.
Error: failed to initialize database: bad configuration: missing field `url`
Error: Rocket failed to launch due to failing fairings:
   >> 'postgres' Database Pool
   >> SQLx Migrations
   >> 'redis' Database Pool

thread 'main' panicked at /Users/icode/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rocket-0.5.1/src/error.rs:279:9:
aborting due to fairing failure(s)
stack backtrace:
   0: rust_begin_unwind
             at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/std/src/panicking.rs:695:5
   1: core::panicking::panic_fmt
             at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/library/core/src/panicking.rs:75:14
   2: core::panicking::panic_display
             at /Volumes/Data/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/panicking.rs:261:5
   3: <rocket::error::Error as core::ops::drop::Drop>::drop::panic_cold_display
             at /Volumes/Data/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/panic.rs:100:13
   4: <rocket::error::Error as core::ops::drop::Drop>::drop
             at /Users/icode/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rocket-0.5.1/src/error.rs:279:9
   5: core::ptr::drop_in_place<rocket::error::Error>
             at /Volumes/Data/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:523:1
   6: core::ptr::drop_in_place<core::result::Result<rocket::rkt::Rocket<rocket::phase::Ignite>,rocket::error::Error>>
             at /Volumes/Data/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:523:1
   7: moke::main
             at ./backend/src/main.rs:62:1
   8: core::ops::function::FnOnce::call_once
             at /Volumes/Data/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Additional Context

No response

System Checks

  • My bug report relates to functionality.
  • I have tested against the latest Rocket release or a recent git commit.
  • I have tested against the latest stable rustc toolchain.
  • I was unable to find this issue previously reported.
@icode icode added the triage A bug report being investigated label Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage A bug report being investigated
Projects
None yet
Development

No branches or pull requests

1 participant
0