Skip to content

Commit c869180

Browse files
feat: mock process for natura2000 data
1 parent cb5d702 commit c869180

File tree

11 files changed

+586
-57
lines changed

11 files changed

+586
-57
lines changed

backend/src/db/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ pub async fn setup_db(config: &crate::config::Database) -> Result<DbPool> {
4545
let db_pool_builder = if cfg!(test) {
4646
db_pool_builder
4747
.max_size(1) // Use a single connection for tests
48-
.connection_customizer(Box::new(TestCustomizer))
48+
.connection_customizer(Box::new(TestCustomizer {
49+
schema: config.schema.clone(),
50+
}))
4951
} else {
5052
db_pool_builder
5153
.max_size(8) // TODO: investigate a good size
@@ -107,7 +109,7 @@ impl CustomizeConnection<AsyncPgConnection, PoolError> for SchemaSettingConnecti
107109
) -> Pin<Box<dyn Future<Output = Result<(), PoolError>> + Send + 'a>> {
108110
let schema = self.schema.clone();
109111
Box::pin(async move {
110-
conn.batch_execute(&format!("SET search_path TO {schema};"))
112+
conn.batch_execute(&format!("SET search_path TO {schema},public;"))
111113
.await
112114
.map_err(PoolError::QueryError)
113115
})
@@ -120,14 +122,21 @@ impl CustomizeConnection<AsyncPgConnection, PoolError> for SchemaSettingConnecti
120122
///
121123
/// Built after [`diesel::r2d2::TestCustomizer`]
122124
#[derive(Debug)]
123-
struct TestCustomizer;
125+
struct TestCustomizer {
126+
schema: String,
127+
}
124128

125129
impl CustomizeConnection<AsyncPgConnection, PoolError> for TestCustomizer {
126130
fn on_acquire<'a>(
127131
&'a self,
128132
conn: &'a mut AsyncPgConnection,
129133
) -> Pin<Box<dyn Future<Output = Result<(), PoolError>> + Send + 'a>> {
134+
let schema = self.schema.clone();
130135
Box::pin(async move {
136+
conn.batch_execute(&format!("SET search_path TO {schema},public;"))
137+
.await
138+
.map_err(PoolError::QueryError)?;
139+
131140
conn.begin_test_transaction()
132141
.await
133142
.map_err(PoolError::QueryError)

0 commit comments

Comments
 (0)