Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ jobs:
- name: Start PostgreSQL
run: |
service postgresql start
psql postgres://geoengine:geoengine@localhost -c "CREATE DATABASE biois;"
sudo -u postgres psql << EOF
\set AUTOCOMMIT on
CREATE DATABASE biois OWNER geoengine;
\c biois
CREATE EXTENSION postgis;
EOF
- name: setup rust build cache
uses: Swatinem/rust-cache@v2
with:
Expand Down
15 changes: 12 additions & 3 deletions backend/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ pub async fn setup_db(config: &crate::config::Database) -> Result<DbPool> {
let db_pool_builder = if cfg!(test) {
db_pool_builder
.max_size(1) // Use a single connection for tests
.connection_customizer(Box::new(TestCustomizer))
.connection_customizer(Box::new(TestCustomizer {
schema: config.schema.clone(),
}))
} else {
db_pool_builder
.max_size(8) // TODO: investigate a good size
Expand Down Expand Up @@ -107,7 +109,7 @@ impl CustomizeConnection<AsyncPgConnection, PoolError> for SchemaSettingConnecti
) -> Pin<Box<dyn Future<Output = Result<(), PoolError>> + Send + 'a>> {
let schema = self.schema.clone();
Box::pin(async move {
conn.batch_execute(&format!("SET search_path TO {schema};"))
conn.batch_execute(&format!("SET search_path TO {schema},public;"))
.await
.map_err(PoolError::QueryError)
})
Expand All @@ -120,14 +122,21 @@ impl CustomizeConnection<AsyncPgConnection, PoolError> for SchemaSettingConnecti
///
/// Built after [`diesel::r2d2::TestCustomizer`]
#[derive(Debug)]
struct TestCustomizer;
struct TestCustomizer {
schema: String,
}

impl CustomizeConnection<AsyncPgConnection, PoolError> for TestCustomizer {
fn on_acquire<'a>(
&'a self,
conn: &'a mut AsyncPgConnection,
) -> Pin<Box<dyn Future<Output = Result<(), PoolError>> + Send + 'a>> {
let schema = self.schema.clone();
Box::pin(async move {
conn.batch_execute(&format!("SET search_path TO {schema},public;"))
.await
.map_err(PoolError::QueryError)?;

conn.begin_test_transaction()
.await
.map_err(PoolError::QueryError)
Expand Down
Loading
Loading