pool
does not live long enough when using AsyncMigrationHarness::new(pool.get().await?)
#268
-
Hi, I have the following error message:
Here is my code: pub async fn new_and_migration() -> Result<Url> {
let admin_url = url_custom_db("postgres")?;
let config = AsyncDieselConnectionManager::new(admin_url);
let pool = Pool::builder().build(config).await?;
let mut conn = pool.get().await?;
// Name the DB
let prefix = std::env::var("TEST_DB_PREFIX").unwrap_or_else(|_| "tst_".into());
let db_name = format!("{}{}", prefix, uuid::Uuid::new_v4());
// Connect to admin and create the DB
create_test_database(&mut conn, &db_name).await?;
let db_url = url_custom_db(&db_name)?;
info!(%db_name, %db_url, "Created test database");
// Run migrations (blocking, but offloaded) against the new DB
let config = AsyncDieselConnectionManager::new(db_url.clone());
let pool: Pool<AsyncPgConnection> = Pool::builder().build(config).await?;
let mut harness = AsyncMigrationHarness::new(pool.get().await?);
harness
.run_pending_migrations(MIGRATIONS)
.map_err(|e| anyhow!("migration failed: {e}"))?;
Ok(db_url)
} Any idea what I'm doing wrong? $ cargo version [dependencies] Running on arch linux. Regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I don't have my code on me right now to verify, but you may want to try replacing the problematic |
Beta Was this translation helpful? Give feedback.
I don't have my code on me right now to verify, but you may want to try replacing the problematic
pool.get()
withpool.get_owned()