@@ -36,10 +36,8 @@ use crate::modelsv2::get_geometry_layer_table;
36
36
use crate :: modelsv2:: get_table;
37
37
use crate :: modelsv2:: prelude:: * ;
38
38
use crate :: modelsv2:: railjson:: persist_railjson;
39
- use crate :: modelsv2:: railjson:: persist_railjson_v2;
40
39
use crate :: modelsv2:: Create ;
41
40
use crate :: modelsv2:: DbConnection ;
42
- use crate :: modelsv2:: DbConnectionPool ;
43
41
use crate :: modelsv2:: DbConnectionPoolV2 ;
44
42
use crate :: tables:: infra:: dsl;
45
43
use editoast_schemas:: infra:: RailJson ;
@@ -77,16 +75,11 @@ pub struct Infra {
77
75
}
78
76
79
77
impl InfraChangeset {
80
- pub async fn persist (
81
- self ,
82
- railjson : RailJson ,
83
- db_pool : Arc < DbConnectionPool > ,
84
- ) -> Result < Infra > {
85
- let conn = & mut db_pool. get ( ) . await ?;
78
+ pub async fn persist ( self , railjson : RailJson , conn : & mut DbConnection ) -> Result < Infra > {
86
79
let infra = self . create ( conn) . await ?;
87
80
// TODO: lock infra for update
88
81
debug ! ( "🛤 Begin importing all railjson objects" ) ;
89
- if let Err ( e) = persist_railjson ( db_pool , infra. id , railjson) . await {
82
+ if let Err ( e) = persist_railjson ( conn , infra. id , railjson) . await {
90
83
error ! ( "Could not import infrastructure {}. Rolling back" , infra. id) ;
91
84
infra. delete ( conn) . await ?;
92
85
return Err ( e) ;
@@ -95,23 +88,6 @@ impl InfraChangeset {
95
88
Ok ( infra)
96
89
}
97
90
98
- pub async fn persist_v2 (
99
- self ,
100
- railjson : RailJson ,
101
- db_pool : Arc < DbConnectionPoolV2 > ,
102
- ) -> Result < Infra > {
103
- let infra = self . create ( db_pool. get ( ) . await ?. deref_mut ( ) ) . await ?;
104
- // TODO: lock infra for update
105
- debug ! ( "🛤 Begin importing all railjson objects" ) ;
106
- if let Err ( e) = persist_railjson_v2 ( db_pool. clone ( ) , infra. id , railjson) . await {
107
- error ! ( "Could not import infrastructure {}. Rolling back" , infra. id) ;
108
- infra. delete ( db_pool. get ( ) . await ?. deref_mut ( ) ) . await ?;
109
- return Err ( e) ;
110
- } ;
111
- debug ! ( "🛤 Import finished successfully" ) ;
112
- Ok ( infra)
113
- }
114
-
115
91
#[ must_use = "builder methods are intended to be chained" ]
116
92
pub fn last_railjson_version ( self ) -> Self {
117
93
self . railjson_version ( RAILJSON_VERSION . to_owned ( ) )
@@ -338,8 +314,6 @@ pub mod tests {
338
314
339
315
use super :: Infra ;
340
316
use crate :: error:: EditoastError ;
341
- use crate :: fixtures:: tests:: db_pool;
342
- use crate :: fixtures:: tests:: IntoFixture ;
343
317
use crate :: modelsv2:: fixtures:: create_empty_infra;
344
318
use crate :: modelsv2:: infra:: DEFAULT_INFRA_VERSION ;
345
319
use crate :: modelsv2:: prelude:: * ;
@@ -379,15 +353,15 @@ pub mod tests {
379
353
380
354
#[ rstest]
381
355
async fn persists_railjson_ko_version ( ) {
382
- let pool = db_pool ( ) ;
356
+ let db_pool = DbConnectionPoolV2 :: for_tests ( ) ;
383
357
let railjson_with_invalid_version = RailJson {
384
358
version : "0" . to_string ( ) ,
385
359
..Default :: default ( )
386
360
} ;
387
361
let res = Infra :: changeset ( )
388
362
. name ( "test" . to_owned ( ) )
389
363
. last_railjson_version ( )
390
- . persist ( railjson_with_invalid_version, pool )
364
+ . persist ( railjson_with_invalid_version, db_pool . get_ok ( ) . deref_mut ( ) )
391
365
. await ;
392
366
assert ! ( res. is_err( ) ) ;
393
367
let expected_error = RailJsonError :: UnsupportedVersion {
@@ -419,14 +393,13 @@ pub mod tests {
419
393
version : RAILJSON_VERSION . to_string ( ) ,
420
394
} ;
421
395
422
- let pool = db_pool ( ) ;
396
+ let db_pool = DbConnectionPoolV2 :: for_tests ( ) ;
423
397
let infra = Infra :: changeset ( )
424
398
. name ( "persist_railjson_ok_infra" . to_owned ( ) )
425
399
. last_railjson_version ( )
426
- . persist ( railjson. clone ( ) , pool . clone ( ) )
400
+ . persist ( railjson. clone ( ) , db_pool . get_ok ( ) . deref_mut ( ) )
427
401
. await
428
- . expect ( "could not persist infra" )
429
- . into_fixture ( pool. clone ( ) ) ;
402
+ . expect ( "could not persist infra" ) ;
430
403
431
404
// THEN
432
405
assert_eq ! ( infra. railjson_version, railjson. version) ;
@@ -436,51 +409,94 @@ pub mod tests {
436
409
objects
437
410
}
438
411
439
- let conn = & mut pool. get ( ) . await . unwrap ( ) ;
440
412
let id = infra. id ;
441
413
442
414
assert_eq ! (
443
- sort:: <BufferStop >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
415
+ sort:: <BufferStop >(
416
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
417
+ . await
418
+ . unwrap( )
419
+ ) ,
444
420
sort( railjson. buffer_stops)
445
421
) ;
446
422
assert_eq ! (
447
- sort:: <Route >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
423
+ sort:: <Route >(
424
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
425
+ . await
426
+ . unwrap( )
427
+ ) ,
448
428
sort( railjson. routes)
449
429
) ;
450
430
assert_eq ! (
451
- sort:: <SwitchType >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
431
+ sort:: <SwitchType >(
432
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
433
+ . await
434
+ . unwrap( )
435
+ ) ,
452
436
sort( railjson. extended_switch_types)
453
437
) ;
454
438
assert_eq ! (
455
- sort:: <Switch >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
439
+ sort:: <Switch >(
440
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
441
+ . await
442
+ . unwrap( )
443
+ ) ,
456
444
sort( railjson. switches)
457
445
) ;
458
446
assert_eq ! (
459
- sort:: <TrackSection >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
447
+ sort:: <TrackSection >(
448
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
449
+ . await
450
+ . unwrap( )
451
+ ) ,
460
452
sort( railjson. track_sections)
461
453
) ;
462
454
assert_eq ! (
463
- sort:: <SpeedSection >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
455
+ sort:: <SpeedSection >(
456
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
457
+ . await
458
+ . unwrap( )
459
+ ) ,
464
460
sort( railjson. speed_sections)
465
461
) ;
466
462
assert_eq ! (
467
- sort:: <NeutralSection >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
463
+ sort:: <NeutralSection >(
464
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
465
+ . await
466
+ . unwrap( )
467
+ ) ,
468
468
sort( railjson. neutral_sections)
469
469
) ;
470
470
assert_eq ! (
471
- sort:: <Electrification >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
471
+ sort:: <Electrification >(
472
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
473
+ . await
474
+ . unwrap( )
475
+ ) ,
472
476
sort( railjson. electrifications)
473
477
) ;
474
478
assert_eq ! (
475
- sort:: <Signal >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
479
+ sort:: <Signal >(
480
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
481
+ . await
482
+ . unwrap( )
483
+ ) ,
476
484
sort( railjson. signals)
477
485
) ;
478
486
assert_eq ! (
479
- sort:: <Detector >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
487
+ sort:: <Detector >(
488
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
489
+ . await
490
+ . unwrap( )
491
+ ) ,
480
492
sort( railjson. detectors)
481
493
) ;
482
494
assert_eq ! (
483
- sort:: <OperationalPoint >( find_all_schemas( conn, id) . await . unwrap( ) ) ,
495
+ sort:: <OperationalPoint >(
496
+ find_all_schemas( db_pool. get_ok( ) . deref_mut( ) , id)
497
+ . await
498
+ . unwrap( )
499
+ ) ,
484
500
sort( railjson. operational_points)
485
501
) ;
486
502
}
0 commit comments