{"record":{"id":"1d9f50bdfd4ee7fa","repo":"transact-rs/sqlx","slug":"database-url-must-be-set","errorCode":null,"errorMessage":"DATABASE_URL must be set","messagePattern":"DATABASE_URL must be set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sqlx-mysql/src/testing/mod.rs","lineNumber":40,"sourceCode":"impl TestSupport for MySql {\n    fn test_context(\n        args: &TestArgs,\n    ) -> impl Future<Output = Result<TestContext<Self>, Error>> + Send + '_ {\n        test_context(args)\n    }\n\n    async fn cleanup_test(db_name: &str) -> Result<(), Error> {\n        let mut conn = MASTER_POOL\n            .get()\n            .expect(\"cleanup_test() invoked outside `#[sqlx::test]`\")\n            .acquire()\n            .await?;\n\n        do_cleanup(&mut conn, db_name).await\n    }\n\n    async fn cleanup_test_dbs() -> Result<Option<usize>, Error> {\n        let url = dotenvy::var(\"DATABASE_URL\").expect(\"DATABASE_URL must be set\");\n\n        let mut conn = MySqlConnection::connect(&url).await?;\n\n        let delete_db_names: Vec<String> = query_scalar(\"select db_name from _sqlx_test_databases\")\n            .fetch_all(&mut conn)\n            .await?;\n\n        if delete_db_names.is_empty() {\n            return Ok(None);\n        }\n\n        let mut deleted_db_names = Vec::with_capacity(delete_db_names.len());\n\n        let mut builder = QueryBuilder::new(\"drop database if exists \");\n\n        for db_name in &delete_db_names {\n            builder.push(db_name);\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/transact-rs/sqlx/blob/03af8bcc5711a1935580a54bea249c219a0c217d/sqlx-mysql/src/testing/mod.rs#L22-L58","documentation":"MySQL `cleanup_test_dbs` removes leftover `_sqlx_test_databases` entries and needs to connect directly to the server, so it reads `DATABASE_URL` via `dotenvy::var(..).expect(..)`. It panics when the variable is not set in the environment or a `.env` file.","triggerScenarios":"Invoking `cleanup_test_dbs` (e.g. via the testing cleanup entry point) without `DATABASE_URL` in the environment and without a `.env` file in the working directory.","commonSituations":"Running `cargo test` from a subdirectory so `.env` at the repo root isn't found; CI pipeline missing the DATABASE_URL secret; dotenvy only loads `.env` from the crate's cwd at runtime.","solutions":["Create a `.env` file in the crate root containing `DATABASE_URL=mysql://user:pass@localhost/db`.","Export DATABASE_URL in the shell/CI before running tests.","Run `cargo test` from the directory containing the `.env` file.","For CI, add the DATABASE_URL environment variable to the test job configuration."],"exampleFix":"// .env\n// before (missing)\n// after\nDATABASE_URL=mysql://root:password@localhost/mysql","handlingStrategy":"validation","validationCode":"// Validate before invoking cleanup:\nlet url = std::env::var(\"DATABASE_URL\")\n    .or_else(|_| dotenvy::var(\"DATABASE_URL\"))\n    .unwrap_or_else(|_| panic!(\"DATABASE_URL must be set (env or .env) before cleanup_test_dbs\"));\nassert!(url.starts_with(\"mysql://\"), \"DATABASE_URL must be a MySQL URL\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Commit a `.env.example` and require `.env` before running tests","Set DATABASE_URL in CI secrets for every test job","Run cargo test from the crate root where .env lives"],"tags":["sqlx","mysql","testing","env-var","panic"],"backgroundTag":"missing-env-var","analyzedSha":"03af8bcc5711a1935580a54bea249c219a0c217d","analyzedAt":"2026-09-03T15:01:28.752Z","contentChangedAt":"2026-09-03T15:01:28.752Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}