Re-enable dependence on external PG instance, while PGLite-oxide has issues with error handling: https://github.com/f0rr0/pglite-oxide/issues/14.

This commit is contained in:
Sebastian Jeltsch
2026-05-06 15:50:32 +02:00
parent c299b0d6cb
commit e567edf758
3 changed files with 40 additions and 33 deletions
+30 -24
View File
@@ -523,30 +523,36 @@ pub async fn test_state(options: Option<TestStateOptions>) -> anyhow::Result<App
tokio::fs::create_dir_all(temp_dir.child("uploads")).await?;
let data_dir = DataDir(temp_dir.path().to_path_buf());
// Start PgLite.
let tcp = false;
let (pg_uri, db) = if tcp {
let db = pglite_oxide::PgliteServer::builder()
.fresh_temporary()
// .temporary()
.start()?;
let use_pglite = false;
let (pg_uri, db) = if use_pglite {
// Start PgLite.
let tcp = false;
if tcp {
let db = pglite_oxide::PgliteServer::builder()
.fresh_temporary()
// .temporary()
.start()?;
(db.connection_uri(), db)
(Some(db.connection_uri()), Some(db))
} else {
// NOTE: `db.connection_uri()` returns rubish for UDS.
let sock = temp_dir.path().join(".s.PGSQL.5432");
let db = pglite_oxide::PgliteServer::builder()
.fresh_temporary()
// .temporary()
.unix(&sock)
.start()?;
let pg_uri = format!(
"postgresql://postgres@/template1?host={}",
temp_dir.path().to_string_lossy()
);
(Some(pg_uri), Some(db))
}
} else {
let sock = temp_dir.path().join(".s.PGSQL.5432");
let db = pglite_oxide::PgliteServer::builder()
// .fresh_temporary()
.temporary()
.unix(&sock)
.start()?;
let pg_uri = format!(
"postgresql://postgres@/template1?host={}",
temp_dir.path().to_string_lossy()
);
(pg_uri, db)
(None, None)
};
println!("PG URI: {pg_uri:?}");
@@ -572,7 +578,7 @@ pub async fn test_state(options: Option<TestStateOptions>) -> anyhow::Result<App
data_dir.clone(),
json_schema_registry.clone(),
vec![],
Some(pg_uri.clone()),
pg_uri.clone(),
)
.await;
@@ -630,7 +636,7 @@ pub async fn test_state(options: Option<TestStateOptions>) -> anyhow::Result<App
object_store,
wasm_runtimes: vec![],
wasm_runtimes_builder: Box::new(|| Ok(vec![])),
pg_uri: Some(pg_uri),
pg_uri,
test_cleanup: vec![Box::new(db), Box::new(temp_dir)],
}),
});
+8 -7
View File
@@ -330,15 +330,16 @@ async fn init_db<'a>(
num_threads: Some(1),
}
} else {
panic!("External Postgres required");
let host = trailbase_sqlite::generic::PgConnection::Host {
host: Some("127.0.0.1".to_string()),
port: Some(5432),
user: Some("postgres".to_string()),
password: Some("example".to_string()),
};
log::warn!("External Postgres required: {host:?}");
trailbase_sqlite::generic::PgOptions {
connection: trailbase_sqlite::generic::PgConnection::Host {
host: Some("127.0.0.1".to_string()),
port: Some(5432),
user: Some("postgres".to_string()),
password: Some("example".to_string()),
},
connection: host,
num_threads: Some(2),
}
})?;
+2 -2
View File
@@ -29,7 +29,7 @@ use crate::r#type::ConnectionType;
// NOTE: We should probably decouple from the impl.
pub use crate::sqlite::executor::{ArcLockGuard, LockError, LockGuard};
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum PgConnection {
Uri(String),
Host {
@@ -40,7 +40,7 @@ pub enum PgConnection {
},
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct PgOptions {
pub connection: PgConnection,
pub num_threads: Option<usize>,