diff --git a/editoast/Cargo.lock b/editoast/Cargo.lock index baa9ae16f6c..9c365123e1d 100644 --- a/editoast/Cargo.lock +++ b/editoast/Cargo.lock @@ -1365,6 +1365,7 @@ dependencies = [ "diesel_json", "editoast_common", "editoast_derive", + "editoast_models", "editoast_schemas", "enum-map", "enumset", @@ -1442,6 +1443,24 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "editoast_models" +version = "0.1.0" +dependencies = [ + "diesel", + "diesel-async", + "editoast_derive", + "futures 0.3.30", + "futures-util", + "openssl", + "postgres-openssl", + "thiserror", + "tokio", + "tokio-postgres", + "tracing", + "url", +] + [[package]] name = "editoast_schemas" version = "0.1.0" diff --git a/editoast/Cargo.toml b/editoast/Cargo.toml index 252bab36c92..2c4a1ee420b 100644 --- a/editoast/Cargo.toml +++ b/editoast/Cargo.toml @@ -9,6 +9,7 @@ members = [ ".", "editoast_common", "editoast_derive", + "editoast_models", "editoast_schemas", "osm_to_railjson", ] @@ -16,14 +17,27 @@ members = [ [workspace.dependencies] chrono = { version = "0.4.38", features = ["serde"] } derivative = "2.2.0" +diesel = { version = "2.1.6", features = [ + "chrono", + "postgres", + "serde_json", + "uuid", +] } +diesel-async = { version = "0.4.1", features = ["deadpool", "postgres"] } editoast_common = { path = "./editoast_common" } +editoast_derive = { path = "./editoast_derive" } +editoast_models = { path = "./editoast_models" } editoast_schemas = { path = "./editoast_schemas" } enum-map = "2.7.3" +futures = "0.3.30" +futures-util = "0.3.30" geojson = "*" geos = { version = "8.3.1", features = ["json"] } mvt = "0.9.3" +openssl = "*" paste = "1.0.15" postgis_diesel = { version = "2.3.1", features = ["serde"] } +postgres-openssl = "0.5.0" rand = "0.8.5" rangemap = "1.5.1" rstest = "0.19.0" @@ -33,7 +47,10 @@ serde_json = "1.0.118" strum = { version = "0.26.3", features = ["derive"] } tempfile = "3.10.1" thiserror = "1.0.61" +tokio = "*" +tokio-postgres = "*" tracing = { version = "0.1.40", features = ["log"] } +url = { version = "2.5.2", features = ["serde"] } utoipa = { version = "4.2.3", features = ["actix_extras", "chrono", "uuid"] } uuid = { version = "1.9.1", features = ["serde", "v4"] } @@ -53,21 +70,17 @@ chrono.workspace = true clap = { version = "4.5.7", features = ["derive", "env"] } colored = "2.1.0" derivative.workspace = true -diesel = { version = "2.1.6", features = [ - "chrono", - "postgres", - "serde_json", - "uuid", -] } -diesel-async = { version = "0.4.1", features = ["deadpool", "postgres"] } +diesel.workspace = true +diesel-async = { workspace = true } diesel_json = "0.2.1" editoast_common = { workspace = true } -editoast_derive = { path = "./editoast_derive" } -editoast_schemas = { workspace = true } +editoast_derive.workspace = true +editoast_models.workspace = true +editoast_schemas.workspace = true enum-map.workspace = true enumset = "1.1.3" -futures = "0.3.30" -futures-util = "*" +futures.workspace = true +futures-util.workspace = true geos.workspace = true heck = "0.5.0" image = "0.25.1" @@ -75,7 +88,7 @@ inventory = "0.3" itertools = "0.13.0" json-patch = { version = "2.0.0", features = ["utoipa"] } mvt.workspace = true -openssl = "*" +openssl.workspace = true opentelemetry = "0.23.0" opentelemetry-datadog = { version = "0.11.0", features = ["reqwest-client"] } opentelemetry-otlp = "0.16.0" @@ -85,7 +98,7 @@ osm_to_railjson = { path = "./osm_to_railjson" } paste.workspace = true pathfinding = "4.10.0" postgis_diesel.workspace = true -postgres-openssl = "0.5.0" +postgres-openssl.workspace = true rand.workspace = true rangemap.workspace = true redis = { version = "0.25.4", features = [ @@ -105,18 +118,19 @@ serde_yaml = "0.9.34" sha1 = "0.10" strum.workspace = true thiserror.workspace = true -tokio = "*" -tokio-postgres = "*" +tokio.workspace = true +tokio-postgres.workspace = true tracing.workspace = true tracing-opentelemetry = "0.24.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } -url = { version = "2.5.2", features = ["serde"] } +url.workspace = true utoipa.workspace = true uuid.workspace = true validator = { version = "0.18.1", features = ["derive"] } [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes", "tokio1"] } +editoast_models = { workspace = true, features = ["testing"] } pretty_assertions = "1.4.0" rstest.workspace = true serial_test = "3.1.1" diff --git a/editoast/editoast_derive/src/model.rs b/editoast/editoast_derive/src/model.rs index 7704c434fab..2c58710943e 100644 --- a/editoast/editoast_derive/src/model.rs +++ b/editoast/editoast_derive/src/model.rs @@ -84,7 +84,7 @@ fn create_functions(config: &Config) -> TokenStream { quote! { #[async_trait::async_trait] impl crate::models::Create for #model_name { - async fn create_conn(self, conn: &mut crate::modelsv2::DbConnection) -> crate::error::Result { + async fn create_conn(self, conn: &mut editoast_models::database::DbConnection) -> crate::error::Result { use #table::table; use diesel_async::RunQueryDsl; @@ -92,7 +92,7 @@ fn create_functions(config: &Config) -> TokenStream { } #[doc = #documentation] - async fn create(self, db_pool: std::sync::Arc) -> crate::error::Result { + async fn create(self, db_pool: std::sync::Arc) -> crate::error::Result { let mut conn = db_pool.get().await?; self.create_conn(&mut conn).await } @@ -126,7 +126,7 @@ fn retrieve_functions(config: &Config) -> TokenStream { quote! { #[async_trait::async_trait] impl crate::models::Retrieve for #model_name { - async fn retrieve_conn(conn: &mut crate::modelsv2::DbConnection, obj_id: i64) -> crate::error::Result> { + async fn retrieve_conn(conn: &mut editoast_models::database::DbConnection, obj_id: i64) -> crate::error::Result> { use #table::table; use #table::dsl; use diesel_async::RunQueryDsl; @@ -142,7 +142,7 @@ fn retrieve_functions(config: &Config) -> TokenStream { } #[doc = #retrieve_documentation] - async fn retrieve(db_pool: std::sync::Arc, id: i64) -> crate::error::Result> { + async fn retrieve(db_pool: std::sync::Arc, id: i64) -> crate::error::Result> { let mut conn = db_pool.get().await?; Self::retrieve_conn(&mut conn, id).await } @@ -174,7 +174,7 @@ fn delete_functions(config: &Config) -> TokenStream { quote! { #[async_trait::async_trait] impl crate::models::Delete for #model_name { - async fn delete_conn(conn: &mut crate::modelsv2::DbConnection, obj_id: i64) -> crate::error::Result { + async fn delete_conn(conn: &mut editoast_models::database::DbConnection, obj_id: i64) -> crate::error::Result { use #table::table; use #table::dsl; use diesel_async::RunQueryDsl; @@ -188,7 +188,7 @@ fn delete_functions(config: &Config) -> TokenStream { } #[doc = #documentation] - async fn delete(db_pool: std::sync::Arc, id: i64) -> crate::error::Result { + async fn delete(db_pool: std::sync::Arc, id: i64) -> crate::error::Result { let mut conn = db_pool.get().await?; Self::delete_conn(&mut conn, id).await } @@ -207,7 +207,7 @@ fn update_functions(config: &Config) -> TokenStream { quote! { #[async_trait::async_trait] impl crate::models::Update for #model_name { - async fn update_conn(self, conn: &mut crate::modelsv2::DbConnection, obj_id: i64) -> crate::error::Result> { + async fn update_conn(self, conn: &mut editoast_models::database::DbConnection, obj_id: i64) -> crate::error::Result> { use #table::table; match diesel::update(table.find(obj_id)).set(&self).get_result(conn).await diff --git a/editoast/editoast_derive/src/modelv2/codegen/count_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/count_impl.rs index 837b257366d..69ac1370efb 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/count_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/count_impl.rs @@ -22,7 +22,7 @@ impl ToTokens for CountImpl { offset, ))] async fn count( - conn: &'async_trait mut crate::modelsv2::DbConnection, + conn: &'async_trait mut editoast_models::database::DbConnection, settings: crate::modelsv2::prelude::SelectionSettings, ) -> crate::error::Result { use diesel::QueryDsl; diff --git a/editoast/editoast_derive/src/modelv2/codegen/create_batch_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/create_batch_impl.rs index 4ba0bf8ef2c..ec27ee9a035 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/create_batch_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/create_batch_impl.rs @@ -31,7 +31,7 @@ impl ToTokens for CreateBatchImpl { I: std::iter::IntoIterator + Send + 'async_trait, C: Default + std::iter::Extend + Send + std::fmt::Debug, >( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, values: I, ) -> crate::error::Result { use crate::modelsv2::Model; diff --git a/editoast/editoast_derive/src/modelv2/codegen/create_batch_with_key_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/create_batch_with_key_impl.rs index 3e06c12a7bc..55af8274612 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/create_batch_with_key_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/create_batch_with_key_impl.rs @@ -36,7 +36,7 @@ impl ToTokens for CreateBatchWithKeyImpl { I: std::iter::IntoIterator + Send + 'async_trait, C: Default + std::iter::Extend<(#ty, Self)> + Send + std::fmt::Debug, >( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, values: I, ) -> crate::error::Result { use crate::models::Identifiable; diff --git a/editoast/editoast_derive/src/modelv2/codegen/create_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/create_impl.rs index 952ec8a8e66..fc1b66ade7b 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/create_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/create_impl.rs @@ -25,7 +25,7 @@ impl ToTokens for CreateImpl { #[tracing::instrument(name = #span_name, skip_all, err)] async fn create( self, - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, ) -> crate::error::Result<#model> { use diesel_async::RunQueryDsl; diesel::insert_into(#table_mod::table) diff --git a/editoast/editoast_derive/src/modelv2/codegen/delete_batch_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/delete_batch_impl.rs index 38c1e70c963..26a1863c165 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/delete_batch_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/delete_batch_impl.rs @@ -30,7 +30,7 @@ impl ToTokens for DeleteBatchImpl { impl crate::modelsv2::DeleteBatch<#ty> for #model { #[tracing::instrument(name = #span_name, skip_all, ret, err, fields(query_ids))] async fn delete_batch + Send + 'async_trait>( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, ids: I, ) -> crate::error::Result { use #table_mod::dsl; diff --git a/editoast/editoast_derive/src/modelv2/codegen/delete_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/delete_impl.rs index eab15a0dcb8..ca6dbe580c6 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/delete_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/delete_impl.rs @@ -23,7 +23,7 @@ impl ToTokens for DeleteImpl { #[tracing::instrument(name = #span_name, skip_all, ret, err, fields(query_id = ?self.#primary_key))] async fn delete( &self, - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, ) -> crate::error::Result { use diesel::prelude::*; use diesel_async::RunQueryDsl; diff --git a/editoast/editoast_derive/src/modelv2/codegen/delete_static_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/delete_static_impl.rs index 2e5bac9a6e9..9f56d1b8df5 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/delete_static_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/delete_static_impl.rs @@ -30,7 +30,7 @@ impl ToTokens for DeleteStaticImpl { impl crate::modelsv2::DeleteStatic<#ty> for #model { #[tracing::instrument(name = #span_name, skip_all, ret, err, fields(query_id))] async fn delete_static( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, #id_ident: #ty, ) -> crate::error::Result { use diesel::prelude::*; diff --git a/editoast/editoast_derive/src/modelv2/codegen/exists_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/exists_impl.rs index e68b3534854..83f727aa750 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/exists_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/exists_impl.rs @@ -30,7 +30,7 @@ impl ToTokens for ExistsImpl { impl crate::modelsv2::Exists<#ty> for #model { #[tracing::instrument(name = #span_name, skip_all, ret, err, fields(query_id))] async fn exists( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, #id_ident: #ty, ) -> crate::error::Result { use diesel::prelude::*; diff --git a/editoast/editoast_derive/src/modelv2/codegen/list_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/list_impl.rs index 2f5bc8d5339..31f7002368d 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/list_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/list_impl.rs @@ -28,7 +28,7 @@ impl ToTokens for ListImpl { offset, ))] async fn list( - conn: &'async_trait mut crate::modelsv2::DbConnection, + conn: &'async_trait mut editoast_models::database::DbConnection, settings: crate::modelsv2::prelude::SelectionSettings, ) -> crate::error::Result> { use diesel::QueryDsl; diff --git a/editoast/editoast_derive/src/modelv2/codegen/retrieve_batch_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/retrieve_batch_impl.rs index ac45559c1f7..eb1c3a0c89d 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/retrieve_batch_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/retrieve_batch_impl.rs @@ -36,7 +36,7 @@ impl ToTokens for RetrieveBatchImpl { I: std::iter::IntoIterator + Send + 'async_trait, C: Default + std::iter::Extend<#model> + Send + std::fmt::Debug, >( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, ids: I, ) -> crate::error::Result { use crate::modelsv2::Model; @@ -72,7 +72,7 @@ impl ToTokens for RetrieveBatchImpl { I: std::iter::IntoIterator + Send + 'async_trait, C: Default + std::iter::Extend<(#ty, #model)> + Send + std::fmt::Debug, >( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, ids: I, ) -> crate::error::Result { use crate::models::Identifiable; diff --git a/editoast/editoast_derive/src/modelv2/codegen/retrieve_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/retrieve_impl.rs index 54448db0c62..3d8f3adbe62 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/retrieve_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/retrieve_impl.rs @@ -32,7 +32,7 @@ impl ToTokens for RetrieveImpl { impl crate::modelsv2::Retrieve<#ty> for #model { #[tracing::instrument(name = #span_name, skip_all, err, fields(query_id))] async fn retrieve( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, #id_ident: #ty, ) -> crate::error::Result> { use diesel::prelude::*; diff --git a/editoast/editoast_derive/src/modelv2/codegen/update_batch_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/update_batch_impl.rs index d1863a359ea..47c680da792 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/update_batch_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/update_batch_impl.rs @@ -41,7 +41,7 @@ impl ToTokens for UpdateBatchImpl { C: Default + std::iter::Extend<#model> + Send + std::fmt::Debug, >( self, - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, ids: I, ) -> crate::error::Result { use crate::modelsv2::Model; @@ -80,7 +80,7 @@ impl ToTokens for UpdateBatchImpl { C: Default + std::iter::Extend<(#ty, #model)> + Send, >( self, - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, ids: I, ) -> crate::error::Result { use crate::models::Identifiable; diff --git a/editoast/editoast_derive/src/modelv2/codegen/update_impl.rs b/editoast/editoast_derive/src/modelv2/codegen/update_impl.rs index 746441a2c16..78b7df50754 100644 --- a/editoast/editoast_derive/src/modelv2/codegen/update_impl.rs +++ b/editoast/editoast_derive/src/modelv2/codegen/update_impl.rs @@ -35,7 +35,7 @@ impl ToTokens for UpdateImpl { #[tracing::instrument(name = #span_name, skip_all, err, fields(query_id))] async fn update( self, - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, #id_ident: #ty, ) -> crate::error::Result> { use diesel::prelude::*; diff --git a/editoast/editoast_models/Cargo.toml b/editoast/editoast_models/Cargo.toml new file mode 100644 index 00000000000..2ab5bcb4149 --- /dev/null +++ b/editoast/editoast_models/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "editoast_models" +version = "0.1.0" +edition = "2021" + +[features] +testing = [] + +[dependencies] +diesel.workspace = true +diesel-async.workspace = true +editoast_derive.workspace = true +futures.workspace = true +futures-util.workspace = true +openssl.workspace = true +postgres-openssl.workspace = true +thiserror.workspace = true +tokio.workspace = true +tokio-postgres.workspace = true +tracing.workspace = true +url.workspace = true diff --git a/editoast/src/modelsv2/database.rs b/editoast/editoast_models/src/database.rs similarity index 100% rename from editoast/src/modelsv2/database.rs rename to editoast/editoast_models/src/database.rs diff --git a/editoast/src/modelsv2/database/connection_error.rs b/editoast/editoast_models/src/database/connection_error.rs similarity index 100% rename from editoast/src/modelsv2/database/connection_error.rs rename to editoast/editoast_models/src/database/connection_error.rs diff --git a/editoast/src/modelsv2/database/connection_pool.rs b/editoast/editoast_models/src/database/connection_pool.rs similarity index 94% rename from editoast/src/modelsv2/database/connection_pool.rs rename to editoast/editoast_models/src/database/connection_pool.rs index f96f8a8502c..53faab05d20 100644 --- a/editoast/src/modelsv2/database/connection_pool.rs +++ b/editoast/editoast_models/src/database/connection_pool.rs @@ -14,9 +14,9 @@ use openssl::ssl::SslVerifyMode; use std::sync::Arc; use url::Url; -#[cfg(test)] +#[cfg(feature = "testing")] use tokio::sync::OwnedRwLockWriteGuard; -#[cfg(test)] +#[cfg(feature = "testing")] use tokio::sync::RwLock; use super::DbConnection; @@ -24,10 +24,10 @@ use super::DbConnectionConfig; use super::DbConnectionError; use super::DbConnectionPool; -#[cfg(test)] +#[cfg(feature = "testing")] pub type DbConnectionV2 = OwnedRwLockWriteGuard>; -#[cfg(not(test))] +#[cfg(not(feature = "testing"))] pub type DbConnectionV2 = Object; /// Wrapper for connection pooling with support for test connections on `cfg(test)` @@ -42,11 +42,11 @@ pub type DbConnectionV2 = Object; #[derive(Clone)] pub struct DbConnectionPoolV2 { pool: Arc>, - #[cfg(test)] + #[cfg(feature = "testing")] test_connection: Option>>>, } -#[cfg(test)] +#[cfg(feature = "testing")] impl Default for DbConnectionPoolV2 { fn default() -> Self { Self::for_tests() @@ -67,7 +67,7 @@ impl DbConnectionPoolV2 { Self::try_from_pool(Arc::new(pool)).await } - #[cfg(test)] + #[cfg(feature = "testing")] async fn get_connection(&self) -> Result { if let Some(test_connection) = &self.test_connection { let connection = test_connection.clone().write_owned().await; @@ -77,7 +77,7 @@ impl DbConnectionPoolV2 { } } - #[cfg(not(test))] + #[cfg(not(feature = "testing"))] async fn get_connection(&self) -> Result { let connection = self.pool.get().await?; Ok(connection) @@ -106,7 +106,7 @@ impl DbConnectionPoolV2 { /// 1. Once a connection is used, it should be dropped **AS SOON AS POSSIBLE**. Failing to do so /// may lead to deadlocks. Example: /// - /// ```rust + /// ```ignore /// let conn = pool.get_ok(); /// // Do something with conn /// @@ -119,7 +119,7 @@ impl DbConnectionPoolV2 { /// that the connection usage follows its acquisition. Failing to do so is equivalent to /// the following example: /// - /// ```rust + /// ```ignore /// let conn_futures = (0..10).map(|_| async { pool.get() }); /// let deadlock = futures::future::join_all(conn_futures).await; /// ``` @@ -130,7 +130,7 @@ impl DbConnectionPoolV2 { /// /// - Don't declare a variable for a single-use connection: /// - /// ```rust + /// ```ignore /// // do /// my_function_using_conn(pool.get().await?.deref_mut()).await; /// // instead of @@ -140,7 +140,7 @@ impl DbConnectionPoolV2 { /// /// - If a connection is used repeatedly, prefer using explicit scoping: /// - /// ```rust + /// ```ignore /// let my_results = { /// let conn = &mut pool.get().await?; /// foo(conn).await + bar(conn).await @@ -152,7 +152,7 @@ impl DbConnectionPoolV2 { /// acquired just before its usage, and dropped just after, **all in the same future**. /// And these futures must all be awaited before attempting to acquire a new connection. /// - /// ```rust + /// ```ignore /// let operations = /// items.into_iter() /// .zip(pool.iter_conn()) @@ -173,7 +173,7 @@ impl DbConnectionPoolV2 { /// /// See [DbConnectionPoolV2::get] for more information on how connections should be used /// in tests. - #[cfg(test)] + #[cfg(feature = "testing")] pub fn get_ok(&self) -> DbConnectionV2 { futures::executor::block_on(self.get()).expect("Failed to get test connection") } @@ -184,7 +184,7 @@ impl DbConnectionPoolV2 { /// /// # Example /// - /// ```rust + /// ```ignore /// let operations = /// items.into_iter() /// .zip(pool.iter_conn()) @@ -203,21 +203,21 @@ impl DbConnectionPoolV2 { std::iter::repeat(self).map(|p| p.get()) } - #[cfg(not(test))] + #[cfg(not(feature = "testing"))] pub async fn try_from_pool( pool: Arc>, ) -> Result { Ok(Self { pool }) } - #[cfg(test)] + #[cfg(feature = "testing")] pub async fn try_from_pool( pool: Arc>, ) -> Result { Self::try_from_pool_test(pool, true).await } - #[cfg(test)] + #[cfg(feature = "testing")] pub async fn try_from_pool_test( pool: Arc>, transaction: bool, @@ -235,7 +235,7 @@ impl DbConnectionPoolV2 { }) } - #[cfg(test)] + #[cfg(feature = "testing")] fn new_for_tests(transaction: bool) -> Self { let url = std::env::var("OSRD_TEST_PG_URL") .unwrap_or_else(|_| String::from("postgresql://osrd:password@localhost/osrd")); @@ -250,7 +250,7 @@ impl DbConnectionPoolV2 { /// This method will create a connection with a transaction that will be rolled back at the end of the test. /// /// You can set the `OSRD_TEST_PG_URL` environment variable to use a custom database url. - #[cfg(test)] + #[cfg(feature = "testing")] pub fn for_tests() -> Self { Self::new_for_tests(true) } @@ -258,7 +258,7 @@ impl DbConnectionPoolV2 { /// Create a connection pool for testing purposes without a transaction /// /// You can set the `OSRD_TEST_PG_URL` environment variable to use a custom database url. - #[cfg(test)] + #[cfg(feature = "testing")] pub fn for_tests_no_transaction() -> Self { Self::new_for_tests(false) } diff --git a/editoast/editoast_models/src/lib.rs b/editoast/editoast_models/src/lib.rs new file mode 100644 index 00000000000..8fd0a6be869 --- /dev/null +++ b/editoast/editoast_models/src/lib.rs @@ -0,0 +1 @@ +pub mod database; diff --git a/editoast/src/error.rs b/editoast/src/error.rs index 189cfffa4bb..7cb76097210 100644 --- a/editoast/src/error.rs +++ b/editoast/src/error.rs @@ -1,6 +1,7 @@ use actix_web::{error::JsonPayloadError, http::StatusCode, HttpResponse, ResponseError}; use colored::Colorize; use diesel::result::Error as DieselError; +use editoast_models::database::DbConnectionError; use redis::RedisError; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; @@ -15,8 +16,6 @@ use tracing::error; use utoipa::ToSchema; use validator::{ValidationErrors, ValidationErrorsKind}; -use crate::modelsv2::database::DbConnectionError; - editoast_common::schemas! { InternalError, } diff --git a/editoast/src/fixtures.rs b/editoast/src/fixtures.rs index 25ec87d5ccc..4ae2fe89b0c 100644 --- a/editoast/src/fixtures.rs +++ b/editoast/src/fixtures.rs @@ -4,10 +4,11 @@ pub mod tests { use std::ops::{Deref, DerefMut}; use std::sync::Arc; + use editoast_models::database::connection_pool::create_connection_pool; + use editoast_models::database::DbConnection; + use editoast_models::database::DbConnectionPool; + use crate::client::PostgresConfig; - use crate::modelsv2::database::connection_pool::create_connection_pool; - use crate::modelsv2::database::DbConnectionPool; - use crate::modelsv2::DbConnection; use crate::{ models::{ self, train_schedule::Mrsp, Identifiable, Pathfinding, PathfindingChangeset, diff --git a/editoast/src/generated_data/buffer_stop.rs b/editoast/src/generated_data/buffer_stop.rs index a366ee21594..5e117e30eec 100644 --- a/editoast/src/generated_data/buffer_stop.rs +++ b/editoast/src/generated_data/buffer_stop.rs @@ -13,8 +13,8 @@ use crate::diesel::ExpressionMethods; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_buffer_stop::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct BufferStopLayer; diff --git a/editoast/src/generated_data/detector.rs b/editoast/src/generated_data/detector.rs index 02590ea5090..6c7d253f737 100644 --- a/editoast/src/generated_data/detector.rs +++ b/editoast/src/generated_data/detector.rs @@ -13,8 +13,8 @@ use crate::diesel::ExpressionMethods; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_detector::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct DetectorLayer; diff --git a/editoast/src/generated_data/electrification.rs b/editoast/src/generated_data/electrification.rs index 3478f3e569b..f58cb920f83 100644 --- a/editoast/src/generated_data/electrification.rs +++ b/editoast/src/generated_data/electrification.rs @@ -13,8 +13,8 @@ use crate::diesel::ExpressionMethods; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_electrification::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct ElectrificationLayer; diff --git a/editoast/src/generated_data/error/mod.rs b/editoast/src/generated_data/error/mod.rs index bc170264a49..22bf86e48b6 100644 --- a/editoast/src/generated_data/error/mod.rs +++ b/editoast/src/generated_data/error/mod.rs @@ -36,7 +36,7 @@ use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::Graph; use crate::infra_cache::InfraCache; use crate::infra_cache::ObjectCache; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::OSRDObject; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/generated_data/mod.rs b/editoast/src/generated_data/mod.rs index 26a0b86839b..a852efec411 100644 --- a/editoast/src/generated_data/mod.rs +++ b/editoast/src/generated_data/mod.rs @@ -38,8 +38,8 @@ use track_section::TrackSectionLayer; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; editoast_common::schemas! { error::schemas(), @@ -169,7 +169,7 @@ pub mod tests { use crate::generated_data::refresh_all; use crate::generated_data::update_all; use crate::modelsv2::fixtures::create_empty_infra; - use crate::modelsv2::DbConnectionPoolV2; + use editoast_models::database::DbConnectionPoolV2; #[rstest] // Slow test async fn refresh_all_test() { diff --git a/editoast/src/generated_data/neutral_section.rs b/editoast/src/generated_data/neutral_section.rs index 68aa16ef857..646cdd50193 100644 --- a/editoast/src/generated_data/neutral_section.rs +++ b/editoast/src/generated_data/neutral_section.rs @@ -7,7 +7,7 @@ use super::GeneratedData; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; pub struct NeutralSectionLayer; diff --git a/editoast/src/generated_data/neutral_sign.rs b/editoast/src/generated_data/neutral_sign.rs index b2eaabadd40..0324d18c99d 100644 --- a/editoast/src/generated_data/neutral_sign.rs +++ b/editoast/src/generated_data/neutral_sign.rs @@ -13,8 +13,8 @@ use crate::diesel::ExpressionMethods; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_neutral_sign::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct NeutralSignLayer; diff --git a/editoast/src/generated_data/operational_point.rs b/editoast/src/generated_data/operational_point.rs index 834f58ef19c..673a80b4a6a 100644 --- a/editoast/src/generated_data/operational_point.rs +++ b/editoast/src/generated_data/operational_point.rs @@ -13,8 +13,8 @@ use crate::diesel::ExpressionMethods; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_operational_point::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct OperationalPointLayer; diff --git a/editoast/src/generated_data/psl_sign.rs b/editoast/src/generated_data/psl_sign.rs index 1efed27a78c..2bba65fc7d3 100644 --- a/editoast/src/generated_data/psl_sign.rs +++ b/editoast/src/generated_data/psl_sign.rs @@ -13,8 +13,8 @@ use crate::diesel::ExpressionMethods; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_psl_sign::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct PSLSignLayer; diff --git a/editoast/src/generated_data/signal.rs b/editoast/src/generated_data/signal.rs index f2d44a4eaff..5f4ea1287a2 100644 --- a/editoast/src/generated_data/signal.rs +++ b/editoast/src/generated_data/signal.rs @@ -17,8 +17,8 @@ use crate::generated_data::sprite_config::SpriteConfig; use crate::generated_data::sprite_config::SpriteConfigs; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_signal::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::infra::LogicalSignal; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/generated_data/speed_section.rs b/editoast/src/generated_data/speed_section.rs index 08496d373b5..fa10f14e8e6 100644 --- a/editoast/src/generated_data/speed_section.rs +++ b/editoast/src/generated_data/speed_section.rs @@ -13,8 +13,8 @@ use crate::diesel::ExpressionMethods; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_speed_section::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct SpeedSectionLayer; diff --git a/editoast/src/generated_data/switch.rs b/editoast/src/generated_data/switch.rs index b559a693fc0..2590db8ba49 100644 --- a/editoast/src/generated_data/switch.rs +++ b/editoast/src/generated_data/switch.rs @@ -10,7 +10,7 @@ use super::GeneratedData; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct SwitchLayer; diff --git a/editoast/src/generated_data/track_section.rs b/editoast/src/generated_data/track_section.rs index 993f31451e7..0662e63aa2d 100644 --- a/editoast/src/generated_data/track_section.rs +++ b/editoast/src/generated_data/track_section.rs @@ -13,8 +13,8 @@ use crate::diesel::ExpressionMethods; use crate::error::Result; use crate::infra_cache::operation::CacheOperation; use crate::infra_cache::InfraCache; -use crate::modelsv2::DbConnection; use crate::tables::infra_layer_track_section::dsl; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub struct TrackSectionLayer; diff --git a/editoast/src/infra_cache/mod.rs b/editoast/src/infra_cache/mod.rs index ef014cde591..e0d84aed87a 100644 --- a/editoast/src/infra_cache/mod.rs +++ b/editoast/src/infra_cache/mod.rs @@ -54,8 +54,8 @@ use crate::infra_cache::object_cache::SwitchCache; use crate::infra_cache::object_cache::TrackSectionCache; use crate::infra_cache::operation::CacheOperation; use crate::modelsv2::railjson::find_all_schemas; -use crate::modelsv2::DbConnection; use crate::modelsv2::Infra; +use editoast_models::database::DbConnection; use editoast_schemas::infra::InfraObject; use editoast_schemas::primitives::BoundingBox; @@ -897,7 +897,7 @@ pub mod tests { use crate::infra_cache::SwitchCache; use crate::modelsv2::fixtures::create_empty_infra; use crate::modelsv2::fixtures::create_infra_object; - use crate::modelsv2::DbConnectionPoolV2; + use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::ApplicableDirections; use editoast_schemas::infra::ApplicableDirectionsTrackRange; use editoast_schemas::infra::Direction; diff --git a/editoast/src/infra_cache/operation/create.rs b/editoast/src/infra_cache/operation/create.rs index 28c17e0bf23..8468dc1df45 100644 --- a/editoast/src/infra_cache/operation/create.rs +++ b/editoast/src/infra_cache/operation/create.rs @@ -7,7 +7,7 @@ use diesel_async::RunQueryDsl; use super::OperationError; use crate::error::Result; use crate::modelsv2::get_table; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; use editoast_schemas::infra::InfraObject; use editoast_schemas::primitives::OSRDIdentified; use editoast_schemas::primitives::OSRDObject; @@ -53,7 +53,7 @@ pub mod tests { paste::paste! { #[rstest::rstest] async fn []() { - let db_pool = crate::modelsv2::DbConnectionPoolV2::for_tests(); + let db_pool = editoast_models::database::DbConnectionPoolV2::for_tests(); let infra = crate::modelsv2::fixtures::create_empty_infra(db_pool.get_ok().deref_mut()).await; let infra_object = editoast_schemas::infra::InfraObject::$obj { railjson: $obj::default(), diff --git a/editoast/src/infra_cache/operation/delete.rs b/editoast/src/infra_cache/operation/delete.rs index 6a0d9355703..1ed3b4a8ee0 100644 --- a/editoast/src/infra_cache/operation/delete.rs +++ b/editoast/src/infra_cache/operation/delete.rs @@ -8,7 +8,7 @@ use serde::Serialize; use super::OperationError; use crate::error::Result; use crate::modelsv2::get_table; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectRef; use editoast_schemas::primitives::ObjectType; @@ -64,6 +64,7 @@ impl From for DeleteOperation { mod tests { use diesel::sql_types::BigInt; + use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::BufferStop; use editoast_schemas::infra::Detector; use editoast_schemas::infra::Electrification; @@ -91,7 +92,7 @@ mod tests { use diesel_async::RunQueryDsl; use std::ops::DerefMut; - let db_pool = crate::modelsv2::DbConnectionPoolV2::for_tests(); + let db_pool = DbConnectionPoolV2::for_tests(); let infra = crate::modelsv2::fixtures::create_empty_infra(db_pool.get_ok().deref_mut()).await; let railjson_object = editoast_schemas::infra::InfraObject::$obj { diff --git a/editoast/src/infra_cache/operation/mod.rs b/editoast/src/infra_cache/operation/mod.rs index b9d666e9224..38c375034bb 100644 --- a/editoast/src/infra_cache/operation/mod.rs +++ b/editoast/src/infra_cache/operation/mod.rs @@ -16,7 +16,7 @@ use utoipa::ToSchema; pub use self::delete::DeleteOperation; use crate::error::Result; use crate::infra_cache::ObjectCache; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; use editoast_schemas::infra::InfraObject; use editoast_schemas::primitives::ObjectRef; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/infra_cache/operation/update.rs b/editoast/src/infra_cache/operation/update.rs index bb8b6601496..d28a6757096 100644 --- a/editoast/src/infra_cache/operation/update.rs +++ b/editoast/src/infra_cache/operation/update.rs @@ -16,7 +16,7 @@ use serde_json::Value; use super::OperationError; use crate::error::Result; use crate::modelsv2::get_table; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; use editoast_schemas::infra::InfraObject; use editoast_schemas::primitives::OSRDIdentified; use editoast_schemas::primitives::ObjectType; @@ -137,7 +137,7 @@ mod tests { use crate::infra_cache::operation::OperationError; use crate::modelsv2::fixtures::create_empty_infra; use crate::modelsv2::fixtures::create_infra_object; - use crate::modelsv2::DbConnectionPoolV2; + use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::TrackSection; use editoast_schemas::primitives::OSRDIdentified; use editoast_schemas::primitives::ObjectType; diff --git a/editoast/src/main.rs b/editoast/src/main.rs index 921f0955ddb..b1764f0fef5 100644 --- a/editoast/src/main.rs +++ b/editoast/src/main.rs @@ -16,8 +16,6 @@ mod views; use crate::core::CoreClient; use crate::error::InternalError; -use crate::modelsv2::DbConnectionPool; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::views::OpenApiRoot; use actix_cors::Cors; @@ -34,6 +32,8 @@ use client::{ ImportRollingStockArgs, ImportTimetableArgs, InfraCloneArgs, InfraCommands, ListProfileSetArgs, MakeMigrationArgs, RedisConfig, RefreshArgs, RunserverArgs, SearchCommands, TimetablesCommands, }; +use editoast_models::database::DbConnectionPool; +use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::ElectricalProfileSetData; use editoast_schemas::rolling_stock::RollingStock; use editoast_schemas::train_schedule::TrainScheduleBase; @@ -46,11 +46,11 @@ use opentelemetry_datadog::DatadogPropagator; use opentelemetry_sdk::propagation::TraceContextPropagator; use views::v2::train_schedule::{TrainScheduleForm, TrainScheduleResult}; -use crate::modelsv2::DbConnection; use colored::*; use diesel::sql_query; use diesel_async::RunQueryDsl; use diesel_json::Json as DieselJson; +use editoast_models::database::DbConnection; use editoast_schemas::infra::RailJson; use infra_cache::InfraCache; use map::MapLayers; diff --git a/editoast/src/models/mod.rs b/editoast/src/models/mod.rs index c4ed2c238cc..a12643b1901 100644 --- a/editoast/src/models/mod.rs +++ b/editoast/src/models/mod.rs @@ -31,9 +31,9 @@ pub use train_schedule::ZoneUpdate; pub use self::pathfinding::*; use crate::error::Result; use crate::modelsv2::projects; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; use crate::views::pagination::PaginatedResponse; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; editoast_common::schemas! { projects::schemas(), diff --git a/editoast/src/models/pathfinding.rs b/editoast/src/models/pathfinding.rs index 422a93feaf4..1f139e34c42 100644 --- a/editoast/src/models/pathfinding.rs +++ b/editoast/src/models/pathfinding.rs @@ -244,7 +244,7 @@ pub mod tests { use super::*; use crate::fixtures::tests::TestFixture; use crate::models::Create; - use crate::modelsv2::DbConnectionPool; + use editoast_models::database::DbConnectionPool; pub fn simple_pathfinding(infra_id: i64) -> Pathfinding { // T1 T2 T3 T4 T5 diff --git a/editoast/src/models/scenario.rs b/editoast/src/models/scenario.rs index 192887927b8..a686a829205 100644 --- a/editoast/src/models/scenario.rs +++ b/editoast/src/models/scenario.rs @@ -23,12 +23,12 @@ use crate::error::Result; use crate::models::train_schedule::LightTrainSchedule; use crate::models::Delete; use crate::models::TextArray; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; use crate::tables::scenario; use crate::views::operational_studies::Ordering; use crate::views::pagination::Paginate; use crate::views::pagination::PaginatedResponse; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; #[derive( Clone, diff --git a/editoast/src/models/timetable.rs b/editoast/src/models/timetable.rs index 739e15ea5a8..9054d9d84b9 100644 --- a/editoast/src/models/timetable.rs +++ b/editoast/src/models/timetable.rs @@ -18,11 +18,11 @@ use crate::models::train_schedule::MechanicalEnergyConsumedBaseEco; use crate::models::train_schedule::TrainSchedule; use crate::models::train_schedule::TrainScheduleSummary; use crate::models::SimulationOutput; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::LightRollingStockModel; use crate::modelsv2::Retrieve; use crate::tables::timetable; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; editoast_common::schemas! { Timetable, diff --git a/editoast/src/models/train_schedule.rs b/editoast/src/models/train_schedule.rs index 844470123a2..d7c65bc154e 100644 --- a/editoast/src/models/train_schedule.rs +++ b/editoast/src/models/train_schedule.rs @@ -17,12 +17,12 @@ use super::check_train_validity; use crate::error::Result; use crate::models::Identifiable; use crate::models::Timetable; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::LightRollingStockModel; use crate::modelsv2::Retrieve; use crate::tables::simulation_output; use crate::tables::train_schedule; use crate::DieselJson; +use editoast_models::database::DbConnectionPool; editoast_common::schemas! { TrainSchedule, diff --git a/editoast/src/modelsv2/electrical_profiles.rs b/editoast/src/modelsv2/electrical_profiles.rs index 8c909e6c5ad..2b90bb51da9 100644 --- a/editoast/src/modelsv2/electrical_profiles.rs +++ b/editoast/src/modelsv2/electrical_profiles.rs @@ -6,8 +6,8 @@ use utoipa::ToSchema; use crate::diesel::QueryDsl; use crate::error::Result; -use crate::modelsv2::DbConnection; use crate::tables::electrical_profile_set; +use editoast_models::database::DbConnection; use editoast_schemas::infra::ElectricalProfileSetData; #[derive(Clone, Debug, Serialize, Deserialize, ModelV2, ToSchema)] @@ -42,7 +42,7 @@ mod tests { use super::*; use crate::modelsv2::fixtures::create_electrical_profile_set; - use crate::modelsv2::DbConnectionPoolV2; + use editoast_models::database::DbConnectionPoolV2; #[rstest] async fn test_list_light() { diff --git a/editoast/src/modelsv2/fixtures.rs b/editoast/src/modelsv2/fixtures.rs index eefc7880701..1c87438bdd5 100644 --- a/editoast/src/modelsv2/fixtures.rs +++ b/editoast/src/modelsv2/fixtures.rs @@ -10,7 +10,6 @@ use crate::modelsv2::prelude::*; use crate::modelsv2::rolling_stock_livery::RollingStockLiveryModel; use crate::modelsv2::timetable::Timetable; use crate::modelsv2::train_schedule::TrainSchedule; -use crate::modelsv2::DbConnection; use crate::modelsv2::Document; use crate::modelsv2::ElectricalProfileSet; use crate::modelsv2::Infra; @@ -21,6 +20,7 @@ use crate::modelsv2::Study; use crate::modelsv2::Tags; use crate::views::rolling_stocks::rolling_stock_form::RollingStockForm; use crate::views::v2::train_schedule::TrainScheduleForm; +use editoast_models::database::DbConnection; pub fn project_changeset(name: &str) -> Changeset { Project::changeset() diff --git a/editoast/src/modelsv2/infra.rs b/editoast/src/modelsv2/infra.rs index 94b206fcd30..01d51394545 100644 --- a/editoast/src/modelsv2/infra.rs +++ b/editoast/src/modelsv2/infra.rs @@ -34,9 +34,9 @@ use crate::modelsv2::get_table; use crate::modelsv2::prelude::*; use crate::modelsv2::railjson::persist_railjson; use crate::modelsv2::Create; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; use crate::tables::infra::dsl; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; use editoast_schemas::infra::RailJson; use editoast_schemas::infra::RAILJSON_VERSION; use editoast_schemas::primitives::ObjectType; @@ -323,7 +323,7 @@ pub mod tests { use crate::modelsv2::prelude::*; use crate::modelsv2::railjson::find_all_schemas; use crate::modelsv2::railjson::RailJsonError; - use crate::modelsv2::DbConnectionPoolV2; + use editoast_models::database::DbConnectionPoolV2; #[rstest] async fn create_infra() { diff --git a/editoast/src/modelsv2/infra/errors.rs b/editoast/src/modelsv2/infra/errors.rs index 71fda843ef7..cd6fe296128 100644 --- a/editoast/src/modelsv2/infra/errors.rs +++ b/editoast/src/modelsv2/infra/errors.rs @@ -6,7 +6,7 @@ use super::Infra; use crate::error::Result; use crate::generated_data::infra_error::{InfraError, InfraErrorTypeLabel}; use crate::modelsv2::pagination::load_for_pagination; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; #[derive(Default, Debug, Clone, PartialEq, Eq, Deserialize, utoipa::ToSchema)] #[serde(rename_all = "lowercase")] diff --git a/editoast/src/modelsv2/infra/object_queryable.rs b/editoast/src/modelsv2/infra/object_queryable.rs index b8a1e4de819..e33aeeae954 100644 --- a/editoast/src/modelsv2/infra/object_queryable.rs +++ b/editoast/src/modelsv2/infra/object_queryable.rs @@ -14,7 +14,7 @@ use super::Infra; use crate::error::Result; use crate::modelsv2::get_geometry_layer_table; use crate::modelsv2::get_table; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; editoast_common::schemas! { ObjectQueryable, diff --git a/editoast/src/modelsv2/infra/railjson_data.rs b/editoast/src/modelsv2/infra/railjson_data.rs index e6ebeb5a2d0..603050ebc16 100644 --- a/editoast/src/modelsv2/infra/railjson_data.rs +++ b/editoast/src/modelsv2/infra/railjson_data.rs @@ -7,7 +7,7 @@ use editoast_schemas::primitives::ObjectType; use super::Infra; use crate::error::Result; use crate::modelsv2::get_table; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; #[derive(QueryableByName, Default)] pub struct RailJsonData { diff --git a/editoast/src/modelsv2/infra/route_from_waypoint_result.rs b/editoast/src/modelsv2/infra/route_from_waypoint_result.rs index dd1bb9a660a..f60035fe047 100644 --- a/editoast/src/modelsv2/infra/route_from_waypoint_result.rs +++ b/editoast/src/modelsv2/infra/route_from_waypoint_result.rs @@ -6,7 +6,7 @@ use diesel_async::RunQueryDsl; use super::Infra; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; #[derive(QueryableByName)] pub struct RouteFromWaypointResult { diff --git a/editoast/src/modelsv2/infra/speed_limit_tags.rs b/editoast/src/modelsv2/infra/speed_limit_tags.rs index a16dc40c0fd..79c803730ce 100644 --- a/editoast/src/modelsv2/infra/speed_limit_tags.rs +++ b/editoast/src/modelsv2/infra/speed_limit_tags.rs @@ -7,7 +7,7 @@ use serde::Serialize; use super::Infra; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; #[derive(QueryableByName, Debug, Clone, Serialize, Deserialize)] pub struct SpeedLimitTags { diff --git a/editoast/src/modelsv2/infra/splited_track_section_with_data.rs b/editoast/src/modelsv2/infra/splited_track_section_with_data.rs index f7ad724a813..5f0b98fd7ce 100644 --- a/editoast/src/modelsv2/infra/splited_track_section_with_data.rs +++ b/editoast/src/modelsv2/infra/splited_track_section_with_data.rs @@ -11,7 +11,7 @@ use serde::Deserialize; use super::Infra; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; #[derive(QueryableByName, Debug, Clone, Deserialize)] pub struct SplitedTrackSectionWithData { diff --git a/editoast/src/modelsv2/infra/voltage.rs b/editoast/src/modelsv2/infra/voltage.rs index a5b2f3889a2..40ead72d154 100644 --- a/editoast/src/modelsv2/infra/voltage.rs +++ b/editoast/src/modelsv2/infra/voltage.rs @@ -7,7 +7,7 @@ use serde::Serialize; use super::Infra; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; #[derive(QueryableByName, Debug, Clone, Serialize, Deserialize)] pub struct Voltage { diff --git a/editoast/src/modelsv2/infra_objects.rs b/editoast/src/modelsv2/infra_objects.rs index 03b7aeb585e..012245d8657 100644 --- a/editoast/src/modelsv2/infra_objects.rs +++ b/editoast/src/modelsv2/infra_objects.rs @@ -6,8 +6,8 @@ use serde::Deserialize; use serde::Serialize; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnection; use crate::tables::*; +use editoast_models::database::DbConnection; use editoast_schemas::primitives::ObjectType; pub trait ModelBackedSchema: Sized { @@ -304,7 +304,7 @@ mod tests_persist { paste::paste! { #[rstest::rstest] async fn []() { - let db_pool = crate::modelsv2::DbConnectionPoolV2::for_tests(); + let db_pool = editoast_models::database::DbConnectionPoolV2::for_tests(); let infra = crate::modelsv2::fixtures::create_empty_infra(db_pool.get_ok().deref_mut()).await; let schemas = (0..10).map(|_| Default::default()); let changesets = $obj::from_infra_schemas(infra.id, schemas); diff --git a/editoast/src/modelsv2/light_rolling_stock.rs b/editoast/src/modelsv2/light_rolling_stock.rs index 13920e00483..89b7bc230b8 100644 --- a/editoast/src/modelsv2/light_rolling_stock.rs +++ b/editoast/src/modelsv2/light_rolling_stock.rs @@ -19,12 +19,12 @@ use utoipa::ToSchema; use super::Row; use crate::error::Result; use crate::modelsv2::rolling_stock_livery::RollingStockLiveryMetadataModel; -use crate::modelsv2::DbConnection; use crate::modelsv2::Model; use crate::views::pagination::Paginate; use crate::views::pagination::PaginatedResponse; use crate::views::rolling_stocks::light_rolling_stock::LightEffortCurves; use crate::views::rolling_stocks::light_rolling_stock::LightRollingStock; +use editoast_models::database::DbConnection; #[derive(Debug, Clone, ModelV2, Serialize, ToSchema)] #[model(table = crate::tables::rolling_stock)] @@ -154,8 +154,8 @@ pub mod tests { use super::LightRollingStockModel; use crate::modelsv2::fixtures::create_fast_rolling_stock; - use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Retrieve; + use editoast_models::database::DbConnectionPoolV2; #[rstest] async fn get_light_rolling_stock() { diff --git a/editoast/src/modelsv2/mod.rs b/editoast/src/modelsv2/mod.rs index 206e01725cf..85bc484091a 100644 --- a/editoast/src/modelsv2/mod.rs +++ b/editoast/src/modelsv2/mod.rs @@ -1,4 +1,3 @@ -pub mod database; pub mod documents; pub mod electrical_profiles; #[cfg(test)] @@ -23,9 +22,6 @@ pub mod work_schedules; pub use prelude::*; -pub use database::DbConnection; -pub use database::DbConnectionPool; -pub use database::DbConnectionPoolV2; pub use documents::Document; pub use electrical_profiles::ElectricalProfileSet; pub use infra::Infra; diff --git a/editoast/src/modelsv2/pagination.rs b/editoast/src/modelsv2/pagination.rs index 472ff268bbd..d2695e76708 100644 --- a/editoast/src/modelsv2/pagination.rs +++ b/editoast/src/modelsv2/pagination.rs @@ -3,11 +3,10 @@ use diesel::query_builder::{AstPass, Query, QueryFragment, QueryId}; use diesel::sql_types::{BigInt, Untyped}; use diesel::{QueryResult, QueryableByName}; use diesel_async::RunQueryDsl; +use editoast_models::database::DbConnection; use crate::error::Result; -use super::DbConnection; - #[derive(QueryId)] struct PaginatedQuery { query: Q, diff --git a/editoast/src/modelsv2/prelude/create.rs b/editoast/src/modelsv2/prelude/create.rs index 561085e15c3..ecdc33d6450 100644 --- a/editoast/src/modelsv2/prelude/create.rs +++ b/editoast/src/modelsv2/prelude/create.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; use crate::error::EditoastError; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; /// Describes how a [Model](super::Model) can be created in the database /// diff --git a/editoast/src/modelsv2/prelude/delete.rs b/editoast/src/modelsv2/prelude/delete.rs index 4a8d0a5d977..82a6ef229cb 100644 --- a/editoast/src/modelsv2/prelude/delete.rs +++ b/editoast/src/modelsv2/prelude/delete.rs @@ -1,6 +1,6 @@ use crate::error::EditoastError; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; /// Describes how a [Model](super::Model) can be deleted from the database /// diff --git a/editoast/src/modelsv2/prelude/list.rs b/editoast/src/modelsv2/prelude/list.rs index c0ef26d9543..107d5014da1 100644 --- a/editoast/src/modelsv2/prelude/list.rs +++ b/editoast/src/modelsv2/prelude/list.rs @@ -6,7 +6,7 @@ use diesel::query_builder::QueryFragment; use diesel::sql_types::{Bool, SqlType}; use std::sync::Arc; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; use super::Model; diff --git a/editoast/src/modelsv2/prelude/retrieve.rs b/editoast/src/modelsv2/prelude/retrieve.rs index fa0829f84a5..48cb3355cb9 100644 --- a/editoast/src/modelsv2/prelude/retrieve.rs +++ b/editoast/src/modelsv2/prelude/retrieve.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; use crate::error::EditoastError; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; /// Describes how a [Model](super::Model) can be retrieved from the database /// diff --git a/editoast/src/modelsv2/prelude/update.rs b/editoast/src/modelsv2/prelude/update.rs index 2d85e2efdcd..3b0568cccad 100644 --- a/editoast/src/modelsv2/prelude/update.rs +++ b/editoast/src/modelsv2/prelude/update.rs @@ -5,7 +5,7 @@ use diesel::result::Error::NotFound; use crate::error::EditoastError; use crate::error::Result; use crate::models::PreferredId; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; use super::Model; diff --git a/editoast/src/modelsv2/projects.rs b/editoast/src/modelsv2/projects.rs index fad210dbdad..968783e2b0e 100644 --- a/editoast/src/modelsv2/projects.rs +++ b/editoast/src/modelsv2/projects.rs @@ -7,11 +7,11 @@ use utoipa::ToSchema; use crate::error::Result; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnection; use crate::modelsv2::Document; use crate::modelsv2::Study; use crate::views::projects::ProjectError; use crate::SelectionSettings; +use editoast_models::database::DbConnection; editoast_common::schemas! { Project, @@ -124,8 +124,8 @@ pub mod test { use super::*; use crate::modelsv2::fixtures::create_project; use crate::modelsv2::prelude::*; - use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Model; + use editoast_models::database::DbConnectionPoolV2; #[rstest] async fn project_creation() { diff --git a/editoast/src/modelsv2/railjson.rs b/editoast/src/modelsv2/railjson.rs index b5e56aa8ac8..7001d0c8e41 100644 --- a/editoast/src/modelsv2/railjson.rs +++ b/editoast/src/modelsv2/railjson.rs @@ -8,8 +8,8 @@ use crate::error::InternalError; use crate::error::Result; use crate::modelsv2::infra_objects::*; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; #[derive(Debug, thiserror::Error, EditoastError)] #[editoast_error(base_id = "railjson")] diff --git a/editoast/src/modelsv2/rolling_stock_livery.rs b/editoast/src/modelsv2/rolling_stock_livery.rs index 301307b2513..4b26fe681d5 100644 --- a/editoast/src/modelsv2/rolling_stock_livery.rs +++ b/editoast/src/modelsv2/rolling_stock_livery.rs @@ -9,8 +9,8 @@ use serde::Serialize; use super::Document; use crate::error::Result; -use crate::modelsv2::DbConnection; use crate::tables::rolling_stock_livery; +use editoast_models::database::DbConnection; /// Rolling Stock Livery /// @@ -88,8 +88,8 @@ pub mod tests { use super::RollingStockLiveryModel; use crate::modelsv2::fixtures::create_rolling_stock_livery_fixture; use crate::modelsv2::prelude::*; - use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Document; + use editoast_models::database::DbConnectionPoolV2; #[rstest] async fn create_delete_rolling_stock_livery() { diff --git a/editoast/src/modelsv2/rolling_stock_model.rs b/editoast/src/modelsv2/rolling_stock_model.rs index 6460bbf791e..a65a8aec54e 100644 --- a/editoast/src/modelsv2/rolling_stock_model.rs +++ b/editoast/src/modelsv2/rolling_stock_model.rs @@ -28,8 +28,8 @@ use validator::ValidationErrors; use crate::error::Result; use crate::modelsv2::prelude::*; use crate::modelsv2::rolling_stock_livery::RollingStockLiveryMetadataModel; -use crate::modelsv2::DbConnection; use crate::views::rolling_stocks::RollingStockWithLiveries; +use editoast_models::database::DbConnection; editoast_common::schemas! { RollingStockModel, @@ -226,9 +226,9 @@ pub mod tests { use crate::modelsv2::fixtures::create_rolling_stock_with_energy_sources; use crate::modelsv2::fixtures::rolling_stock_with_energy_sources_changeset; use crate::modelsv2::prelude::*; - use crate::modelsv2::DbConnectionPoolV2; use crate::views::rolling_stocks::map_diesel_error; use crate::views::rolling_stocks::RollingStockError; + use editoast_models::database::DbConnectionPoolV2; #[rstest] async fn update_rolling_stock() { diff --git a/editoast/src/modelsv2/rolling_stock_model/power_restrictions.rs b/editoast/src/modelsv2/rolling_stock_model/power_restrictions.rs index 0f55467e181..fa4769eb8f4 100644 --- a/editoast/src/modelsv2/rolling_stock_model/power_restrictions.rs +++ b/editoast/src/modelsv2/rolling_stock_model/power_restrictions.rs @@ -7,7 +7,7 @@ use utoipa::ToSchema; use super::RollingStockModel; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; editoast_common::schemas! { PowerRestriction, diff --git a/editoast/src/modelsv2/rolling_stock_model/rolling_stock_usage.rs b/editoast/src/modelsv2/rolling_stock_model/rolling_stock_usage.rs index bb539510b14..20cd139fe20 100644 --- a/editoast/src/modelsv2/rolling_stock_model/rolling_stock_usage.rs +++ b/editoast/src/modelsv2/rolling_stock_model/rolling_stock_usage.rs @@ -8,7 +8,7 @@ use utoipa::ToSchema; use super::RollingStockModel; use crate::error::Result; -use crate::modelsv2::DbConnection; +use editoast_models::database::DbConnection; editoast_common::schemas! { TrainScheduleScenarioStudyProject, diff --git a/editoast/src/modelsv2/scenario.rs b/editoast/src/modelsv2/scenario.rs index 5b01549d3f0..385e26dd2e5 100644 --- a/editoast/src/modelsv2/scenario.rs +++ b/editoast/src/modelsv2/scenario.rs @@ -8,8 +8,8 @@ use serde_derive::Serialize; use utoipa::ToSchema; use crate::error::Result; -use crate::modelsv2::DbConnection; use crate::modelsv2::Tags; +use editoast_models::database::DbConnection; #[derive(Debug, Clone, ModelV2, Deserialize, Serialize, ToSchema)] #[schema(as = ScenarioV2)] diff --git a/editoast/src/modelsv2/study.rs b/editoast/src/modelsv2/study.rs index c63df41660c..e5f1eaedec6 100644 --- a/editoast/src/modelsv2/study.rs +++ b/editoast/src/modelsv2/study.rs @@ -10,8 +10,8 @@ use utoipa::ToSchema; use crate::error::Result; use crate::modelsv2::prelude::*; use crate::modelsv2::projects::Tags; -use crate::modelsv2::DbConnection; use crate::modelsv2::Scenario; +use editoast_models::database::DbConnection; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ModelV2, ToSchema)] #[model(table = crate::tables::study)] @@ -90,7 +90,7 @@ pub mod test { use super::*; use crate::modelsv2::fixtures::create_project; use crate::modelsv2::fixtures::create_study; - use crate::modelsv2::DbConnectionPoolV2; + use editoast_models::database::DbConnectionPoolV2; #[rstest] async fn study_retrieve() { diff --git a/editoast/src/modelsv2/timetable.rs b/editoast/src/modelsv2/timetable.rs index 9187a49536f..bab5c1217db 100644 --- a/editoast/src/modelsv2/timetable.rs +++ b/editoast/src/modelsv2/timetable.rs @@ -5,8 +5,8 @@ use diesel::sql_types::Nullable; use editoast_derive::ModelV2; use crate::error::Result; -use crate::modelsv2::DbConnection; use crate::modelsv2::Retrieve; +use editoast_models::database::DbConnection; #[derive(Debug, Default, Clone, ModelV2)] #[model(table = crate::tables::timetable_v2)] diff --git a/editoast/src/views/documents.rs b/editoast/src/views/documents.rs index 4bb9abcce0b..c8b31048546 100644 --- a/editoast/src/views/documents.rs +++ b/editoast/src/views/documents.rs @@ -14,8 +14,8 @@ use thiserror::Error; use utoipa::ToSchema; use crate::error::Result; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::*; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/documents" => { diff --git a/editoast/src/views/electrical_profiles.rs b/editoast/src/views/electrical_profiles.rs index f15ad80a6d2..f9e955fb5aa 100644 --- a/editoast/src/views/electrical_profiles.rs +++ b/editoast/src/views/electrical_profiles.rs @@ -17,10 +17,10 @@ use crate::error::Result; use crate::modelsv2::electrical_profiles::ElectricalProfileSet; use crate::modelsv2::electrical_profiles::LightElectricalProfileSet; use crate::modelsv2::Create; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::DeleteStatic; use crate::modelsv2::Model; use crate::modelsv2::Retrieve; +use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::ElectricalProfileSetData; use editoast_schemas::infra::LevelValues; diff --git a/editoast/src/views/infra/attached.rs b/editoast/src/views/infra/attached.rs index 1e98640b610..84c869405a7 100644 --- a/editoast/src/views/infra/attached.rs +++ b/editoast/src/views/infra/attached.rs @@ -12,9 +12,9 @@ use thiserror::Error; use crate::error::Result; use crate::infra_cache::InfraCache; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::views::infra::InfraApiError; +use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::primitives::ObjectType; crate::routes! { attached } diff --git a/editoast/src/views/infra/auto_fixes/mod.rs b/editoast/src/views/infra/auto_fixes/mod.rs index fe05389c096..856fc20ac2c 100644 --- a/editoast/src/views/infra/auto_fixes/mod.rs +++ b/editoast/src/views/infra/auto_fixes/mod.rs @@ -24,10 +24,10 @@ use crate::infra_cache::operation::UpdateOperation; use crate::infra_cache::InfraCache; use crate::infra_cache::ObjectCache; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Infra; use crate::views::infra::InfraApiError; use crate::views::infra::InfraIdParam; +use editoast_models::database::DbConnectionPool; use editoast_schemas::infra::InfraObject; use editoast_schemas::primitives::OSRDIdentified as _; use editoast_schemas::primitives::OSRDObject; diff --git a/editoast/src/views/infra/edition.rs b/editoast/src/views/infra/edition.rs index b310978a0bf..bf2ae901e30 100644 --- a/editoast/src/views/infra/edition.rs +++ b/editoast/src/views/infra/edition.rs @@ -36,12 +36,12 @@ use crate::infra_cache::ObjectCache; use crate::map; use crate::map::MapLayers; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Infra; use crate::views::infra::InfraApiError; use crate::views::infra::InfraIdParam; use crate::RedisClient; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; use editoast_schemas::infra::InfraObject; crate::routes! { diff --git a/editoast/src/views/infra/errors.rs b/editoast/src/views/infra/errors.rs index 941f6573ca6..7eb4a1dce07 100644 --- a/editoast/src/views/infra/errors.rs +++ b/editoast/src/views/infra/errors.rs @@ -16,11 +16,11 @@ use crate::generated_data::infra_error::InfraError; use crate::generated_data::infra_error::InfraErrorTypeLabel; use crate::modelsv2::infra::errors::Level; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::views::infra::InfraIdParam; use crate::views::pagination::PaginationQueryParam; use crate::views::pagination::PaginationStats; +use editoast_models::database::DbConnectionPoolV2; use super::InfraApiError; @@ -115,7 +115,7 @@ enum ListErrorsErrors { #[cfg(test)] pub(in crate::views) async fn query_errors( - conn: &mut crate::modelsv2::DbConnection, + conn: &mut editoast_models::database::DbConnection, infra: &Infra, ) -> (Vec, u64) { infra diff --git a/editoast/src/views/infra/lines.rs b/editoast/src/views/infra/lines.rs index 7177e9166f9..63e0ab6722f 100644 --- a/editoast/src/views/infra/lines.rs +++ b/editoast/src/views/infra/lines.rs @@ -11,10 +11,10 @@ use crate::error::Result; use crate::infra_cache::InfraCache; use crate::infra_cache::ObjectCache; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::views::infra::InfraApiError; use crate::views::infra::InfraIdParam; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/lines/{line_code}/bbox" => { diff --git a/editoast/src/views/infra/mod.rs b/editoast/src/views/infra/mod.rs index ec2db081c4a..e287e9ffe07 100644 --- a/editoast/src/views/infra/mod.rs +++ b/editoast/src/views/infra/mod.rs @@ -42,12 +42,12 @@ use crate::infra_cache::ObjectCache; use crate::map; use crate::map::MapLayers; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPool; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::views::pagination::PaginatedList as _; use crate::views::pagination::PaginationQueryParam; use crate::RedisClient; +use editoast_models::database::DbConnectionPool; +use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::SwitchType; crate::routes! { diff --git a/editoast/src/views/infra/objects.rs b/editoast/src/views/infra/objects.rs index d49813bb52d..178a107bac5 100644 --- a/editoast/src/views/infra/objects.rs +++ b/editoast/src/views/infra/objects.rs @@ -1,22 +1,22 @@ use std::collections::HashMap; use std::collections::HashSet; +use std::ops::DerefMut; use actix_web::post; use actix_web::web::Data; use actix_web::web::Json; use actix_web::web::Path; use editoast_derive::EditoastError; -use std::ops::DerefMut; +use editoast_models::database::DbConnectionPoolV2; +use editoast_schemas::primitives::ObjectType; use thiserror::Error; use super::InfraApiError; use super::InfraIdParam; use crate::error::Result; use crate::modelsv2::infra::ObjectQueryable; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::Retrieve; -use editoast_schemas::primitives::ObjectType; crate::routes! { get_objects, diff --git a/editoast/src/views/infra/pathfinding.rs b/editoast/src/views/infra/pathfinding.rs index b0ed64eb970..c89615864d7 100644 --- a/editoast/src/views/infra/pathfinding.rs +++ b/editoast/src/views/infra/pathfinding.rs @@ -20,10 +20,10 @@ use crate::error::Result; use crate::infra_cache::Graph; use crate::infra_cache::InfraCache; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::views::infra::InfraApiError; use crate::views::infra::InfraIdParam; +use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::Direction; use editoast_schemas::infra::DirectionalTrackRange; use editoast_schemas::infra::Endpoint; diff --git a/editoast/src/views/infra/railjson.rs b/editoast/src/views/infra/railjson.rs index 141808c5e47..eb88c609655 100644 --- a/editoast/src/views/infra/railjson.rs +++ b/editoast/src/views/infra/railjson.rs @@ -23,10 +23,10 @@ use utoipa::ToSchema; use crate::error::Result; use crate::infra_cache::InfraCache; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Infra; use crate::views::infra::InfraApiError; use crate::views::infra::InfraIdParam; +use editoast_models::database::DbConnectionPool; use editoast_schemas::primitives::ObjectType; crate::routes! { diff --git a/editoast/src/views/infra/routes.rs b/editoast/src/views/infra/routes.rs index e1b26d90a11..3d4ca33815e 100644 --- a/editoast/src/views/infra/routes.rs +++ b/editoast/src/views/infra/routes.rs @@ -18,12 +18,12 @@ use crate::error::Result; use crate::infra_cache::Graph; use crate::infra_cache::InfraCache; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPool; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::views::infra::InfraApiError; use crate::views::infra::InfraIdParam; use crate::views::params::List; +use editoast_models::database::DbConnectionPool; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/routes" => { diff --git a/editoast/src/views/layers/mod.rs b/editoast/src/views/layers/mod.rs index 7e825169636..6013e82743e 100644 --- a/editoast/src/views/layers/mod.rs +++ b/editoast/src/views/layers/mod.rs @@ -30,8 +30,8 @@ use crate::map::get_view_cache_prefix; use crate::map::Layer; use crate::map::MapLayers; use crate::map::Tile; -use crate::modelsv2::DbConnectionPoolV2; use crate::RedisClient; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/layers" => { diff --git a/editoast/src/views/light_rolling_stocks.rs b/editoast/src/views/light_rolling_stocks.rs index ab9c71924a7..0389be6c2fb 100644 --- a/editoast/src/views/light_rolling_stocks.rs +++ b/editoast/src/views/light_rolling_stocks.rs @@ -6,7 +6,6 @@ use actix_web::web::Query; use crate::decl_paginated_response; use crate::error::Result; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::LightRollingStockModel; use crate::modelsv2::Retrieve; use crate::views::pagination::PaginatedResponse; @@ -15,6 +14,7 @@ use crate::views::rolling_stocks::RollingStockError; use crate::views::rolling_stocks::RollingStockIdParam; use crate::views::rolling_stocks::RollingStockKey; use crate::views::rolling_stocks::RollingStockNameParam; +use editoast_models::database::DbConnectionPoolV2; use super::rolling_stocks::light_rolling_stock::LightRollingStockWithLiveries; diff --git a/editoast/src/views/mod.rs b/editoast/src/views/mod.rs index e9b5e675bb1..0df898c9b40 100644 --- a/editoast/src/views/mod.rs +++ b/editoast/src/views/mod.rs @@ -48,8 +48,8 @@ use crate::generated_data; use crate::infra_cache::operation; use crate::models; use crate::modelsv2; -use crate::modelsv2::DbConnectionPoolV2; use crate::RedisClient; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { (health, version, core_version), diff --git a/editoast/src/views/pagination.rs b/editoast/src/views/pagination.rs index 3bd059c260c..145b00aa7f2 100644 --- a/editoast/src/views/pagination.rs +++ b/editoast/src/views/pagination.rs @@ -15,10 +15,10 @@ use utoipa::IntoParams; use utoipa::ToSchema; use crate::error::Result; -use crate::modelsv2::DbConnection; use crate::ListAndCount; use crate::Model; use crate::SelectionSettings; +use editoast_models::database::DbConnection; editoast_common::schemas! { PaginationStats, diff --git a/editoast/src/views/pathfinding/electrical_profiles.rs b/editoast/src/views/pathfinding/electrical_profiles.rs index 4a384b934d2..e0d10ddfd41 100644 --- a/editoast/src/views/pathfinding/electrical_profiles.rs +++ b/editoast/src/views/pathfinding/electrical_profiles.rs @@ -19,13 +19,13 @@ use crate::error::Result; use crate::models::pathfinding::Pathfinding; use crate::models::Retrieve; use crate::modelsv2::electrical_profiles::ElectricalProfileSet; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::LightRollingStockModel; use crate::views::electrical_profiles::ElectricalProfilesError; use crate::views::pathfinding::path_rangemap::make_path_range_map; use crate::views::pathfinding::path_rangemap::TrackMap; use crate::views::pathfinding::PathfindingError; use crate::views::pathfinding::PathfindingIdParam; +use editoast_models::database::DbConnectionPool; use editoast_schemas::infra::ElectricalProfileSetData; crate::routes! { diff --git a/editoast/src/views/pathfinding/electrifications.rs b/editoast/src/views/pathfinding/electrifications.rs index 305ae03ffee..ab97f57fc84 100644 --- a/editoast/src/views/pathfinding/electrifications.rs +++ b/editoast/src/views/pathfinding/electrifications.rs @@ -18,13 +18,13 @@ use crate::error::Result; use crate::infra_cache::InfraCache; use crate::models::pathfinding::Pathfinding; use crate::models::Retrieve; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Infra; use crate::modelsv2::Retrieve as RetrieveV2; use crate::views::pathfinding::path_rangemap::make_path_range_map; use crate::views::pathfinding::path_rangemap::TrackMap; use crate::views::pathfinding::PathfindingError; use crate::views::pathfinding::PathfindingIdParam; +use editoast_models::database::DbConnectionPool; use editoast_schemas::primitives::ObjectType; crate::routes! { diff --git a/editoast/src/views/pathfinding/mod.rs b/editoast/src/views/pathfinding/mod.rs index 614bd6b12b0..21c23a6c619 100644 --- a/editoast/src/views/pathfinding/mod.rs +++ b/editoast/src/views/pathfinding/mod.rs @@ -48,12 +48,12 @@ use crate::models::Retrieve; use crate::models::Slope; use crate::models::Update; use crate::modelsv2::infra_objects::TrackSectionModel; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Infra; use crate::modelsv2::OperationalPointModel; use crate::modelsv2::Retrieve as RetrieveV2; use crate::modelsv2::RollingStockModel; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; use editoast_schemas::infra::ApplicableDirectionsTrackRange; use editoast_schemas::infra::OperationalPoint; use editoast_schemas::infra::TrackSection; diff --git a/editoast/src/views/projects.rs b/editoast/src/views/projects.rs index 9de67c55b84..72828d57945 100644 --- a/editoast/src/views/projects.rs +++ b/editoast/src/views/projects.rs @@ -26,13 +26,13 @@ use crate::error::Result; use crate::modelsv2::projects::Tags; use crate::modelsv2::Changeset; use crate::modelsv2::Create; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Document; use crate::modelsv2::Model; use crate::modelsv2::Project; use crate::modelsv2::Retrieve; use crate::views::pagination::PaginationQueryParam; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/projects" => { diff --git a/editoast/src/views/rolling_stocks/mod.rs b/editoast/src/views/rolling_stocks/mod.rs index ec41b793173..18b8e791da1 100644 --- a/editoast/src/views/rolling_stocks/mod.rs +++ b/editoast/src/views/rolling_stocks/mod.rs @@ -39,12 +39,12 @@ use crate::error::Result; use crate::modelsv2::prelude::*; use crate::modelsv2::rolling_stock_livery::RollingStockLiveryModel; use crate::modelsv2::rolling_stock_model::TrainScheduleScenarioStudyProject; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Document; use crate::modelsv2::RollingStockModel; use crate::modelsv2::RollingStockSeparatedImageModel; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/rolling_stock" => { diff --git a/editoast/src/views/scenario.rs b/editoast/src/views/scenario.rs index c4446fea3e0..66aa12d312b 100644 --- a/editoast/src/views/scenario.rs +++ b/editoast/src/views/scenario.rs @@ -33,8 +33,6 @@ use crate::models::ScenarioWithCountTrains; use crate::models::ScenarioWithDetails; use crate::models::Timetable; use crate::models::Update; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Project; use crate::modelsv2::Study; use crate::views::pagination::PaginatedResponse; @@ -43,6 +41,8 @@ use crate::views::projects::ProjectError; use crate::views::projects::ProjectIdParam; use crate::views::study::StudyError; use crate::views::study::StudyIdParam; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; crate::routes! { "/scenarios" => { diff --git a/editoast/src/views/search/mod.rs b/editoast/src/views/search/mod.rs index 5f7866c5e54..cab4c9dc375 100644 --- a/editoast/src/views/search/mod.rs +++ b/editoast/src/views/search/mod.rs @@ -232,8 +232,8 @@ use self::searchast::SearchAst; use self::typing::AstType; use self::typing::TypeSpec; use crate::error::Result; -use crate::modelsv2::DbConnectionPool; use crate::views::pagination::PaginationQueryParam; +use editoast_models::database::DbConnectionPool; crate::routes! { search diff --git a/editoast/src/views/single_simulation.rs b/editoast/src/views/single_simulation.rs index 96245ef08fe..58afd25453f 100644 --- a/editoast/src/views/single_simulation.rs +++ b/editoast/src/views/single_simulation.rs @@ -27,9 +27,9 @@ use crate::models::train_schedule::TrainScheduleOptions; use crate::models::Pathfinding; use crate::models::Retrieve; use crate::modelsv2::electrical_profiles::ElectricalProfileSet; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Exists; use crate::modelsv2::RollingStockModel; +use editoast_models::database::DbConnectionPool; #[derive(Debug, Error, EditoastError)] #[editoast_error(base_id = "single_simulation")] diff --git a/editoast/src/views/stdcm/mod.rs b/editoast/src/views/stdcm/mod.rs index e8a7af70fb2..de08ed4cf42 100644 --- a/editoast/src/views/stdcm/mod.rs +++ b/editoast/src/views/stdcm/mod.rs @@ -36,9 +36,9 @@ use crate::models::PathfindingPayload; use crate::models::SpacingRequirement; use crate::models::TrainSchedule; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Infra; use crate::views::rolling_stocks::retrieve_existing_rolling_stock; +use editoast_models::database::DbConnectionPool; crate::routes! { "/stdcm" => { diff --git a/editoast/src/views/study.rs b/editoast/src/views/study.rs index da7a9a4c9a6..4fa4c47c769 100644 --- a/editoast/src/views/study.rs +++ b/editoast/src/views/study.rs @@ -27,8 +27,9 @@ use super::scenario; use crate::error::InternalError; use crate::error::Result; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPoolV2; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPoolV2; + use crate::modelsv2::Project; use crate::modelsv2::Study; use crate::modelsv2::Tags; diff --git a/editoast/src/views/test_app.rs b/editoast/src/views/test_app.rs index 882f9afa994..c231e9b87c1 100644 --- a/editoast/src/views/test_app.rs +++ b/editoast/src/views/test_app.rs @@ -14,6 +14,8 @@ use actix_web::{ App, Error, }; use chashmap::CHashMap; +use editoast_models::database::connection_pool::create_connection_pool; +use editoast_models::database::DbConnectionPoolV2; use serde::de::DeserializeOwned; use tracing::Instrument as _; @@ -23,7 +25,7 @@ use crate::{ error::InternalError, infra_cache::InfraCache, map::MapLayers, - modelsv2::{database::connection_pool::create_connection_pool, DbConnectionPoolV2}, + // modelsv2::{database::connection_pool::create_connection_pool, DbConnectionPoolV2}, RedisClient, }; diff --git a/editoast/src/views/timetable.rs b/editoast/src/views/timetable.rs index ff6f854bb2a..77ccbbc7e56 100644 --- a/editoast/src/views/timetable.rs +++ b/editoast/src/views/timetable.rs @@ -22,8 +22,8 @@ use crate::models::SimulationOutput; use crate::models::Timetable; use crate::models::TimetableWithSchedulesDetails; use crate::models::TrainSchedule; -use crate::modelsv2::DbConnectionPool; use crate::views::train_schedule::TrainScheduleError; +use editoast_models::database::DbConnectionPool; mod import; diff --git a/editoast/src/views/timetable/import.rs b/editoast/src/views/timetable/import.rs index 681dab7da0b..80dc080a783 100644 --- a/editoast/src/views/timetable/import.rs +++ b/editoast/src/views/timetable/import.rs @@ -30,8 +30,6 @@ use crate::models::ScheduledPoint; use crate::models::Timetable; use crate::models::TrainSchedule; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::Infra; use crate::modelsv2::OperationalPointModel; use crate::modelsv2::RetrieveBatch; @@ -43,6 +41,8 @@ use crate::views::pathfinding::save_core_pathfinding; use crate::views::timetable::Path; use crate::views::timetable::TimetableError; use crate::views::train_schedule::process_simulation_response; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; use editoast_schemas::infra::OperationalPointPart; crate::routes! { diff --git a/editoast/src/views/train_schedule/mod.rs b/editoast/src/views/train_schedule/mod.rs index 95e45b66544..da80190fe11 100644 --- a/editoast/src/views/train_schedule/mod.rs +++ b/editoast/src/views/train_schedule/mod.rs @@ -55,7 +55,6 @@ use crate::models::Timetable; use crate::models::TrainSchedule; use crate::models::TrainScheduleChangeset; use crate::models::Update; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::ElectricalProfileSet; use crate::modelsv2::Infra; use crate::modelsv2::LightRollingStockModel; @@ -66,6 +65,7 @@ use crate::tables; use crate::views::infra::InfraApiError; use crate::views::train_schedule::simulation_report::fetch_simulation_output; use crate::DieselJson; +use editoast_models::database::DbConnectionPool; crate::routes! { "/train_schedule" => { diff --git a/editoast/src/views/train_schedule/simulation_report.rs b/editoast/src/views/train_schedule/simulation_report.rs index d0f74e65270..a77c9d84fec 100644 --- a/editoast/src/views/train_schedule/simulation_report.rs +++ b/editoast/src/views/train_schedule/simulation_report.rs @@ -30,11 +30,11 @@ use crate::models::SimulationOutput; use crate::models::SimulationOutputChangeset; use crate::models::Slope; use crate::models::TrainSchedule; -use crate::modelsv2::DbConnectionPool; use crate::modelsv2::RollingStockModel; use crate::views::pathfinding::make_track_map; use crate::views::train_schedule::projection::Projection; use crate::views::train_schedule::TrainScheduleError::UnsimulatedTrainSchedule; +use editoast_models::database::DbConnectionPool; use editoast_schemas::primitives::Identifier; editoast_common::schemas! { diff --git a/editoast/src/views/v2/path.rs b/editoast/src/views/v2/path.rs index 493e24591bd..86a76c8832a 100644 --- a/editoast/src/views/v2/path.rs +++ b/editoast/src/views/v2/path.rs @@ -10,8 +10,8 @@ use thiserror::Error; use crate::core::v2::pathfinding::TrackRange; use crate::error::Result; use crate::modelsv2::prelude::*; -use crate::modelsv2::DbConnection; use crate::modelsv2::Infra; +use editoast_models::database::DbConnection; /// Expiration time for the cache of the pathfinding and path properties. /// Note: 604800 seconds = 1 week diff --git a/editoast/src/views/v2/path/pathfinding.rs b/editoast/src/views/v2/path/pathfinding.rs index c2f2617aeaa..087046d8ea8 100644 --- a/editoast/src/views/v2/path/pathfinding.rs +++ b/editoast/src/views/v2/path/pathfinding.rs @@ -22,8 +22,6 @@ use crate::core::AsCoreRequest; use crate::core::CoreClient; use crate::error::Result; use crate::modelsv2::train_schedule::TrainSchedule; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::modelsv2::OperationalPointModel; use crate::modelsv2::Retrieve; @@ -35,6 +33,8 @@ use crate::redis_utils::RedisClient; use crate::redis_utils::RedisConnection; use crate::views::get_app_version; use crate::views::v2::path::PathfindingError; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::OperationalPoint; type TrackOffsetResult = std::result::Result>, TrackOffsetExtractionError>; diff --git a/editoast/src/views/v2/path/properties.rs b/editoast/src/views/v2/path/properties.rs index 0cd388b1392..c3f7099f80c 100644 --- a/editoast/src/views/v2/path/properties.rs +++ b/editoast/src/views/v2/path/properties.rs @@ -31,11 +31,11 @@ use crate::core::v2::pathfinding::TrackRange; use crate::core::AsCoreRequest; use crate::core::CoreClient; use crate::error::Result; -use crate::modelsv2::DbConnectionPoolV2; use crate::views::v2::path::retrieve_infra_version; use crate::RedisClient; use crate::RedisConnection; use editoast_common::geometry::GeoJsonLineString; +use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::OperationalPointExtensions; use editoast_schemas::infra::OperationalPointPart; diff --git a/editoast/src/views/v2/scenario.rs b/editoast/src/views/v2/scenario.rs index 3e20072be0d..0512b311616 100644 --- a/editoast/src/views/v2/scenario.rs +++ b/editoast/src/views/v2/scenario.rs @@ -26,8 +26,6 @@ use crate::models::train_schedule::LightTrainSchedule; use crate::modelsv2::prelude::*; use crate::modelsv2::scenario::Scenario; use crate::modelsv2::timetable::Timetable; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::modelsv2::Project; use crate::modelsv2::Study; @@ -41,6 +39,8 @@ use crate::views::projects::ProjectIdParam; use crate::views::scenario::ScenarioIdParam; use crate::views::study::StudyError; use crate::views::study::StudyIdParam; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/v2/projects/{project_id}/studies/{study_id}/scenarios" => { diff --git a/editoast/src/views/v2/timetable.rs b/editoast/src/views/v2/timetable.rs index 1f4b7642245..738f262611b 100644 --- a/editoast/src/views/v2/timetable.rs +++ b/editoast/src/views/v2/timetable.rs @@ -33,7 +33,6 @@ use crate::modelsv2::timetable::Timetable; use crate::modelsv2::timetable::TimetableWithTrains; use crate::modelsv2::train_schedule::TrainSchedule; use crate::modelsv2::train_schedule::TrainScheduleChangeset; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Infra; use crate::views::pagination::PaginatedList; use crate::views::pagination::PaginationQueryParam; @@ -44,6 +43,7 @@ use crate::views::v2::train_schedule::TrainScheduleResult; use crate::CoreClient; use crate::RedisClient; use crate::RetrieveBatch; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/v2/timetable" => { diff --git a/editoast/src/views/v2/timetable/stdcm.rs b/editoast/src/views/v2/timetable/stdcm.rs index 40a34f4d0a4..a9c1e1cdc63 100644 --- a/editoast/src/views/v2/timetable/stdcm.rs +++ b/editoast/src/views/v2/timetable/stdcm.rs @@ -29,15 +29,16 @@ use crate::error::Result; use crate::modelsv2::timetable::TimetableWithTrains; use crate::modelsv2::train_schedule::TrainSchedule; use crate::modelsv2::work_schedules::WorkSchedule; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::RollingStockModel; -use crate::modelsv2::{DbConnection, Infra, List}; +use crate::modelsv2::{Infra, List}; use crate::views::v2::path::pathfinding::extract_location_from_path_items; use crate::views::v2::path::pathfinding::TrackOffsetExtractionError; use crate::views::v2::train_schedule::{train_simulation, train_simulation_batch}; use crate::RedisClient; use crate::Retrieve; use crate::RetrieveBatch; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPoolV2; crate::routes! { "/stdcm" => { diff --git a/editoast/src/views/v2/train_schedule.rs b/editoast/src/views/v2/train_schedule.rs index 4f57314261d..e0b047bc520 100644 --- a/editoast/src/views/v2/train_schedule.rs +++ b/editoast/src/views/v2/train_schedule.rs @@ -44,13 +44,13 @@ use crate::modelsv2::prelude::*; use crate::modelsv2::timetable::Timetable; use crate::modelsv2::train_schedule::TrainSchedule; use crate::modelsv2::train_schedule::TrainScheduleChangeset; -use crate::modelsv2::DbConnection; -use crate::modelsv2::DbConnectionPool; -use crate::modelsv2::DbConnectionPoolV2; use crate::views::v2::path::pathfinding_from_train; use crate::views::v2::path::PathfindingError; use crate::RedisClient; use crate::RollingStockModel; +use editoast_models::database::DbConnection; +use editoast_models::database::DbConnectionPool; +use editoast_models::database::DbConnectionPoolV2; const CACHE_SIMULATION_EXPIRATION: u64 = 604800; // 1 week diff --git a/editoast/src/views/v2/train_schedule/projection.rs b/editoast/src/views/v2/train_schedule/projection.rs index b5d706447c2..d6d520ceb08 100644 --- a/editoast/src/views/v2/train_schedule/projection.rs +++ b/editoast/src/views/v2/train_schedule/projection.rs @@ -33,7 +33,6 @@ use crate::core::CoreClient; use crate::error::Result; use crate::modelsv2::infra::Infra; use crate::modelsv2::train_schedule::TrainSchedule; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Retrieve; use crate::modelsv2::RetrieveBatch; use crate::views::v2::path::pathfinding_from_train; @@ -44,6 +43,7 @@ use crate::views::v2::train_schedule::CompleteReportTrain; use crate::views::v2::train_schedule::ReportTrain; use crate::views::v2::train_schedule::SignalSighting; use crate::views::v2::train_schedule::ZoneUpdate; +use editoast_models::database::DbConnectionPoolV2; use crate::RedisClient; use crate::RollingStockModel; diff --git a/editoast/src/views/work_schedules.rs b/editoast/src/views/work_schedules.rs index dae8ab538b0..186994cc311 100644 --- a/editoast/src/views/work_schedules.rs +++ b/editoast/src/views/work_schedules.rs @@ -20,8 +20,8 @@ use crate::modelsv2::work_schedules::WorkScheduleType; use crate::modelsv2::Changeset; use crate::modelsv2::Create; use crate::modelsv2::CreateBatch; -use crate::modelsv2::DbConnectionPoolV2; use crate::modelsv2::Model; +use editoast_models::database::DbConnectionPoolV2; use editoast_schemas::infra::TrackRange; crate::routes! {