-
Hi there, I'm having trouble understanding how to enable the "migrate" feature. I've added the # Cargo.toml
sqlx = { version = "0.7.3", features = [
"uuid",
"chrono",
"runtime-tokio",
"postgres",
"tls-rustls",
"migrate",
"macros",
] }
uuid = { version = "1.4", features = ["v4", "serde"] }
[features]
migrate = ["sqlx/migrate"] But when I want to use the I have a database specifically for testing, but it only added the _sqlx_migrations table, but not the table that migration would add. Below is my test: #[sqlx::test(migrations = "migrations")]
async fn get_one_note_should_pass() {
dotenv().ok();
let database_url = env::var("TEST_DATABASE_URL").expect("Missing DATABASE_URL env");
let pool = PgPoolOptions::new()
.max_connections(1)
.connect(&database_url)
.await
.unwrap_or_else(|err| {
eprintln!("Failed to connect to database: {:?}", err);
panic!("Database connection error")
});
let result = get_one_note(
&pool,
Uuid::parse_str("e26ccf37-aaa7-4031-a67b-d16a3f990632").unwrap(),
)
.await;
assert!(result.is_ok(), "Error: {:?}", result);
if let Ok(note) = result {
assert_eq!(note.title, "hello world".to_string());
}
} What am I doing wrong specifically? Or do I need to add the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The error mentions automatic database management and to see the docs. If you pull up the docs for All the information should be there. |
Beta Was this translation helpful? Give feedback.
The error mentions automatic database management and to see the docs.
If you pull up the docs for
#[sqlx::test]
you'll see a heading titled "Automatic Test Database Management": https://docs.rs/sqlx/latest/sqlx/attr.test.html#automatic-test-database-management-requires-migrate-featureAll the information should be there.