Skip to content

Commit c339b26

Browse files
committed
editoast: remove DbPool V1 support
Signed-off-by: Leo Valais <[email protected]>
1 parent 02ccfc8 commit c339b26

22 files changed

+52
-83
lines changed

editoast/editoast_models/src/db_connection_pool.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ use url::Url;
2727
use tokio::sync::OwnedRwLockWriteGuard;
2828
use tokio::sync::RwLock;
2929

30-
use super::DbConnectionPool;
31-
use super::DieselConnection;
32-
3330
pub type DbConnectionConfig = AsyncDieselConnectionManager<AsyncPgConnection>;
3431

3532
#[derive(Clone)]
@@ -110,7 +107,7 @@ impl DerefMut for WriteHandle {
110107
///
111108
/// # Testing pool
112109
///
113-
/// In test mode, the [DbConnectionPool::get] function will always return the same connection that has
110+
/// In test mode, the [Pool::<AsyncPgConnection>::get] function will always return the same connection that has
114111
/// been setup to drop all modification once the test ends.
115112
/// Since this connection will not commit any changes to the database, we ensure the isolation of each test.
116113
///
@@ -423,17 +420,17 @@ pub async fn ping_database(conn: &mut DbConnection) -> Result<(), PingError> {
423420
Ok(())
424421
}
425422

426-
pub fn create_connection_pool(
423+
fn create_connection_pool(
427424
url: Url,
428425
max_size: usize,
429-
) -> Result<DbConnectionPool, DatabasePoolBuildError> {
426+
) -> Result<Pool<AsyncPgConnection>, DatabasePoolBuildError> {
430427
let mut manager_config = ManagerConfig::default();
431428
manager_config.custom_setup = Box::new(establish_connection);
432429
let manager = DbConnectionConfig::new_with_config(url, manager_config);
433430
Ok(Pool::builder(manager).max_size(max_size).build()?)
434431
}
435432

436-
fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<DieselConnection>> {
433+
fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConnection>> {
437434
let fut = async {
438435
let mut connector_builder = SslConnector::builder(SslMethod::tls()).unwrap();
439436
connector_builder.set_verify(SslVerifyMode::NONE);
@@ -448,7 +445,7 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<DieselConnec
448445
tracing::error!("connection error: {}", e);
449446
}
450447
});
451-
DieselConnection::try_from(client).await
448+
AsyncPgConnection::try_from(client).await
452449
};
453450
fut.boxed()
454451
}

editoast/editoast_models/src/lib.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
use diesel_async::pooled_connection::deadpool::Pool;
2-
use diesel_async::AsyncPgConnection;
3-
41
pub mod db_connection_pool;
52
pub mod tables;
63

74
pub use db_connection_pool::DbConnection;
85
pub use db_connection_pool::DbConnectionPoolV2;
96

10-
type DieselConnection = AsyncPgConnection;
11-
pub type DbConnectionPool = Pool<DieselConnection>;
12-
137
/// Generic error type to forward errors from the database
148
///
159
/// Useful for functions which only points of failure are the DB calls.
1610
#[derive(Debug, thiserror::Error)]
17-
#[error("an error occured while querying the database: {0}")]
11+
#[error("an error occurred while querying the database: {0}")]
1812
pub struct DatabaseError(#[from] diesel::result::Error);

editoast/src/models/fixtures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ops::DerefMut;
44

55
use chrono::Utc;
66
use editoast_models::DbConnection;
7-
use editoast_models::DbConnectionPool;
7+
88
use editoast_models::DbConnectionPoolV2;
99
use editoast_schemas::infra::Direction;
1010
use editoast_schemas::infra::DirectionalTrackRange;

editoast/src/views/infra/attached.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async fn attached(
6767
Path(InfraAttachedParams { infra_id, track_id }): Path<InfraAttachedParams>,
6868
State(AppState {
6969
infra_caches,
70-
db_pool_v2: db_pool,
70+
db_pool,
7171
..
7272
}): State<AppState>,
7373
Extension(auth): AuthenticationExt,

editoast/src/views/infra/auto_fixes/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async fn list_auto_fixes(
8787
Path(infra_id): Path<i64>,
8888
State(AppState {
8989
infra_caches,
90-
db_pool_v2: db_pool,
90+
db_pool,
9191
..
9292
}): State<AppState>,
9393
Extension(auth): AuthenticationExt,

editoast/src/views/infra/delimited_area.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async fn delimited_area(
129129
Extension(auth): AuthenticationExt,
130130
State(AppState {
131131
infra_caches,
132-
db_pool_v2: db_pool,
132+
db_pool,
133133
..
134134
}): State<AppState>,
135135
Path(InfraIdParam { infra_id }): Path<InfraIdParam>,

editoast/src/views/infra/edition.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ crate::routes! {
7171
async fn edit<'a>(
7272
Path(InfraIdParam { infra_id }): Path<InfraIdParam>,
7373
State(AppState {
74-
db_pool_v2: db_pool,
74+
db_pool,
7575
infra_caches,
7676
valkey,
7777
map_layers,
@@ -126,7 +126,7 @@ async fn edit<'a>(
126126
pub async fn split_track_section<'a>(
127127
Path(InfraIdParam { infra_id }): Path<InfraIdParam>,
128128
State(AppState {
129-
db_pool_v2: db_pool,
129+
db_pool,
130130
infra_caches,
131131
valkey,
132132
map_layers,

editoast/src/views/infra/lines.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async fn get_line_bbox(
4545
Path((infra_id, line_code)): Path<(i64, i64)>,
4646
State(AppState {
4747
infra_caches,
48-
db_pool_v2: db_pool,
48+
db_pool,
4949
..
5050
}): State<AppState>,
5151
Extension(auth): AuthenticationExt,

editoast/src/views/infra/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async fn refresh(
135135
return Err(AuthorizationError::Unauthorized.into());
136136
}
137137

138-
let db_pool = app_state.db_pool_v2.clone();
138+
let db_pool = app_state.db_pool.clone();
139139
let valkey_client = app_state.valkey.clone();
140140
let infra_caches = app_state.infra_caches.clone();
141141
let map_layers = app_state.map_layers.clone();
@@ -212,7 +212,7 @@ async fn list(
212212
if !authorized {
213213
return Err(AuthorizationError::Unauthorized.into());
214214
}
215-
let db_pool = app_state.db_pool_v2.clone();
215+
let db_pool = app_state.db_pool.clone();
216216
let osrdyne_client = app_state.osrdyne_client.clone();
217217

218218
let settings = pagination_params
@@ -307,7 +307,7 @@ async fn get(
307307
return Err(AuthorizationError::Unauthorized.into());
308308
}
309309

310-
let db_pool = app_state.db_pool_v2.clone();
310+
let db_pool = app_state.db_pool.clone();
311311
let osrdyne_client = app_state.osrdyne_client.clone();
312312

313313
let infra_id = infra.infra_id;
@@ -433,7 +433,7 @@ async fn delete(
433433
return Err(AuthorizationError::Unauthorized.into());
434434
}
435435

436-
let db_pool = app_state.db_pool_v2.clone();
436+
let db_pool = app_state.db_pool.clone();
437437
let infra_caches = app_state.infra_caches.clone();
438438
let infra_id = infra.infra_id;
439439
if Infra::fast_delete_static(db_pool.get().await?, infra_id).await? {
@@ -513,7 +513,7 @@ async fn get_switch_types(
513513
return Err(AuthorizationError::Unauthorized.into());
514514
}
515515

516-
let db_pool = app_state.db_pool_v2.clone();
516+
let db_pool = app_state.db_pool.clone();
517517
let conn = &mut db_pool.get().await?;
518518
let infra_caches = app_state.infra_caches.clone();
519519

@@ -724,7 +724,7 @@ async fn load(
724724
return Err(AuthorizationError::Unauthorized.into());
725725
}
726726

727-
let db_pool = app_state.db_pool_v2.clone();
727+
let db_pool = app_state.db_pool.clone();
728728
let core_client = app_state.core_client.clone();
729729

730730
let infra_id = path.infra_id;

editoast/src/views/infra/pathfinding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async fn pathfinding_view(
110110
return Err(AuthorizationError::Unauthorized.into());
111111
}
112112

113-
let db_pool = app_state.db_pool_v2.clone();
113+
let db_pool = app_state.db_pool.clone();
114114
let infra_caches = app_state.infra_caches.clone();
115115

116116
// Parse and check input

editoast/src/views/infra/railjson.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async fn post_railjson(
181181
return Err(AuthorizationError::Unauthorized.into());
182182
}
183183

184-
let db_pool = app_state.db_pool_v2.clone();
184+
let db_pool = app_state.db_pool.clone();
185185
let infra_caches = app_state.infra_caches.clone();
186186
if railjson.version != RAILJSON_VERSION {
187187
return Err(ListErrorsRailjson::WrongRailjsonVersionProvided.into());

editoast/src/views/infra/routes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async fn get_routes_track_ranges(
158158
return Err(AuthorizationError::Unauthorized.into());
159159
}
160160

161-
let db_pool = app_state.db_pool_v2.clone();
161+
let db_pool = app_state.db_pool.clone();
162162
let infra_caches = app_state.infra_caches.clone();
163163
let infra_id = infra;
164164
let infra = Infra::retrieve_or_fail(&mut db_pool.get().await?, infra_id, || {
@@ -219,7 +219,7 @@ async fn get_routes_nodes(
219219
return Err(AuthorizationError::Unauthorized.into());
220220
}
221221

222-
let db_pool = app_state.db_pool_v2.clone();
222+
let db_pool = app_state.db_pool.clone();
223223
let infra_caches = app_state.infra_caches.clone();
224224

225225
let infra = Infra::retrieve_or_fail(&mut db_pool.get().await?, params.infra_id, || {

editoast/src/views/layers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ struct TileParams {
179179
async fn cache_and_get_mvt_tile(
180180
State(AppState {
181181
map_layers,
182-
db_pool_v2: db_pool,
182+
db_pool,
183183
valkey,
184184
..
185185
}): State<AppState>,

editoast/src/views/mod.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use dashmap::DashMap;
4141
use editoast_authz::authorizer::Authorizer;
4242
use editoast_authz::authorizer::UserInfo;
4343
use editoast_authz::BuiltinRole;
44-
use editoast_models::DbConnectionPool;
44+
4545
use editoast_osrdyne_client::OsrdyneClient;
4646
use futures::TryFutureExt;
4747
pub use openapi::OpenApiRoot;
@@ -225,7 +225,7 @@ async fn authenticate(
225225

226226
async fn authentication_middleware(
227227
State(AppState {
228-
db_pool_v2: db_pool,
228+
db_pool,
229229
disable_authorization,
230230
..
231231
}): State<AppState>,
@@ -278,7 +278,7 @@ pub enum AppHealthError {
278278
)]
279279
async fn health(
280280
State(AppState {
281-
db_pool_v2: db_pool,
281+
db_pool,
282282
valkey,
283283
health_check_timeout,
284284
core_client,
@@ -384,8 +384,7 @@ pub struct Server {
384384
pub struct AppState {
385385
pub config: Arc<ServerConfig>,
386386

387-
pub db_pool_v1: Arc<DbConnectionPool>,
388-
pub db_pool_v2: Arc<DbConnectionPoolV2>,
387+
pub db_pool: Arc<DbConnectionPoolV2>,
389388
pub valkey: Arc<ValkeyClient>,
390389
pub infra_caches: Arc<DashMap<i64, InfraCache>>,
391390
pub map_layers: Arc<MapLayers>,
@@ -398,7 +397,7 @@ pub struct AppState {
398397

399398
impl FromRef<AppState> for DbConnectionPoolV2 {
400399
fn from_ref(input: &AppState) -> Self {
401-
(*input.db_pool_v2).clone()
400+
(*input.db_pool).clone()
402401
}
403402
}
404403

@@ -409,16 +408,15 @@ impl AppState {
409408
// Config database
410409
let valkey = ValkeyClient::new(config.valkey_config.clone())?.into();
411410

412-
// Create both database pools
413-
let db_pool_v2 = {
411+
// Create database pool
412+
let db_pool = {
414413
let PostgresConfig {
415414
database_url,
416415
pool_size,
417416
} = config.postgres_config.clone();
418-
DbConnectionPoolV2::try_initialize(database_url, pool_size).await?
417+
let pool = DbConnectionPoolV2::try_initialize(database_url, pool_size).await?;
418+
Arc::new(pool)
419419
};
420-
let db_pool_v1 = db_pool_v2.pool_v1();
421-
let db_pool_v2 = Arc::new(db_pool_v2);
422420

423421
// Setup infra cache map
424422
let infra_caches = DashMap::<i64, InfraCache>::default().into();
@@ -449,8 +447,7 @@ impl AppState {
449447

450448
Ok(Self {
451449
valkey,
452-
db_pool_v1,
453-
db_pool_v2,
450+
db_pool,
454451
infra_caches,
455452
core_client,
456453
osrdyne_client,

editoast/src/views/path/pathfinding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub enum PathfindingFailure {
158158
)]
159159
async fn post(
160160
State(AppState {
161-
db_pool_v2: db_pool,
161+
db_pool,
162162
valkey,
163163
core_client,
164164
..

editoast/src/views/path/properties.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ type Properties = EnumSet<Property>;
164164
)]
165165
async fn post(
166166
State(AppState {
167-
db_pool_v2: db_pool,
167+
db_pool,
168168
valkey,
169169
core_client,
170170
..

editoast/src/views/stdcm_search_environment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async fn overwrite(
118118
return Err(AuthorizationError::Unauthorized.into());
119119
}
120120

121-
let db_pool = app_state.db_pool_v2.clone();
121+
let db_pool = app_state.db_pool.clone();
122122
let conn = &mut db_pool.get().await?;
123123

124124
let changeset: Changeset<StdcmSearchEnvironment> = form.into();
@@ -146,7 +146,7 @@ async fn retrieve_latest(
146146
return Err(AuthorizationError::Unauthorized.into());
147147
}
148148

149-
let db_pool = app_state.db_pool_v2.clone();
149+
let db_pool = app_state.db_pool.clone();
150150
let conn = &mut db_pool.get().await?;
151151

152152
let search_env = StdcmSearchEnvironment::retrieve_latest(conn).await;

0 commit comments

Comments
 (0)