From 6423baf4313686dca896cd14e577383e6368bc73 Mon Sep 17 00:00:00 2001 From: Simone Cottini Date: Thu, 8 Feb 2024 11:03:17 +0100 Subject: [PATCH 1/2] Update dockerfile rust image to 1.75 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab96c0c7..92f1964f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM public.ecr.aws/prima/rust:1.69.0 +FROM public.ecr.aws/prima/rust:1.75.0 WORKDIR /code COPY entrypoint /code/entrypoint -RUN cargo install sqlx-cli --no-default-features --features native-tls,postgres --version 0.6.2 +RUN cargo install sqlx-cli --no-default-features --features native-tls,postgres --version 0.7.1 RUN chown -R app:app /code From 929ea030df3149bb2a1225e6c0b09088809dbef4 Mon Sep 17 00:00:00 2001 From: Simone Cottini Date: Thu, 8 Feb 2024 11:46:58 +0100 Subject: [PATCH 2/2] Refactor common to avoid having to publicly expose event_handlers with pub use --- examples/aggregate_deletion/main.rs | 5 ++++- examples/common/basic/event_handler.rs | 3 ++- examples/common/basic/mod.rs | 6 ++---- examples/common/basic/view.rs | 2 +- examples/common/lib.rs | 18 +++++------------- examples/common/shared/event_handler.rs | 4 +++- examples/common/shared/mod.rs | 7 ++----- examples/common/shared/view.rs | 2 +- examples/event_bus/main.rs | 5 ++++- examples/event_bus/rabbit.rs | 2 +- examples/eventual_view/main.rs | 5 ++++- examples/locking_strategies/main.rs | 3 ++- examples/multi_aggregate_rebuild/main.rs | 9 ++++++--- .../transactional_event_handler.rs | 4 +++- examples/readme/main.rs | 10 ++++------ examples/rebuilder/event_handler.rs | 5 +++-- examples/rebuilder/main.rs | 4 +++- .../rebuilder/transactional_event_handler.rs | 3 ++- examples/saga/main.rs | 3 ++- examples/shared_view/main.rs | 9 ++++++--- examples/store_crud/main.rs | 3 ++- examples/transactional_view/main.rs | 4 +++- .../transactional_event_handler.rs | 3 ++- 23 files changed, 67 insertions(+), 52 deletions(-) diff --git a/examples/aggregate_deletion/main.rs b/examples/aggregate_deletion/main.rs index 9428e6e8..f41fb0e0 100644 --- a/examples/aggregate_deletion/main.rs +++ b/examples/aggregate_deletion/main.rs @@ -9,7 +9,10 @@ use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::store::{EventStore, StoreEvent}; use esrs::AggregateState; -use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicError, BasicEvent, BasicEventHandler, BasicView}; +use crate::common::basic::event_handler::BasicEventHandler; +use crate::common::basic::view::BasicView; +use crate::common::basic::{BasicAggregate, BasicCommand, BasicError, BasicEvent}; +use crate::common::util::new_pool; #[path = "../common/lib.rs"] mod common; diff --git a/examples/common/basic/event_handler.rs b/examples/common/basic/event_handler.rs index 41619e76..f93faec5 100644 --- a/examples/common/basic/event_handler.rs +++ b/examples/common/basic/event_handler.rs @@ -5,7 +5,8 @@ use uuid::Uuid; use esrs::handler::EventHandler; use esrs::store::StoreEvent; -use crate::common::{BasicAggregate, BasicEvent, BasicView}; +use crate::common::basic::view::BasicView; +use crate::common::basic::{BasicAggregate, BasicEvent}; #[derive(Clone)] pub struct BasicEventHandler { diff --git a/examples/common/basic/mod.rs b/examples/common/basic/mod.rs index 993001b9..55b1e1b2 100644 --- a/examples/common/basic/mod.rs +++ b/examples/common/basic/mod.rs @@ -1,11 +1,9 @@ use serde::{Deserialize, Serialize}; use esrs::Aggregate; -pub use event_handler::*; -pub use view::*; -mod event_handler; -mod view; +pub mod event_handler; +pub mod view; #[derive(Clone)] pub struct BasicAggregate; diff --git a/examples/common/basic/view.rs b/examples/common/basic/view.rs index 733d93fa..fcc3bc24 100644 --- a/examples/common/basic/view.rs +++ b/examples/common/basic/view.rs @@ -1,7 +1,7 @@ use sqlx::{Executor, Pool, Postgres}; use uuid::Uuid; -use crate::common::random_letters; +use crate::common::util::random_letters; #[derive(sqlx::FromRow, Debug)] pub struct BasicViewRow { diff --git a/examples/common/lib.rs b/examples/common/lib.rs index b2304802..69d86ea1 100644 --- a/examples/common/lib.rs +++ b/examples/common/lib.rs @@ -1,23 +1,15 @@ //! Common structs shared between all the other examples -pub use a::*; -pub use b::*; +pub mod a; +pub mod b; #[cfg(feature = "postgres")] -pub use basic::*; -#[cfg(feature = "postgres")] -pub use shared::*; -pub use util::*; - -mod a; -mod b; -#[cfg(feature = "postgres")] -mod basic; +pub mod basic; #[allow(dead_code)] #[cfg(feature = "postgres")] -mod shared; +pub mod shared; -mod util; +pub mod util; #[derive(Debug, thiserror::Error)] pub enum CommonError {} diff --git a/examples/common/shared/event_handler.rs b/examples/common/shared/event_handler.rs index 5e3c9658..27450d1c 100644 --- a/examples/common/shared/event_handler.rs +++ b/examples/common/shared/event_handler.rs @@ -4,7 +4,9 @@ use sqlx::{Pool, Postgres}; use esrs::handler::{EventHandler, ReplayableEventHandler}; use esrs::store::StoreEvent; -use crate::common::{AggregateA, AggregateB, EventA, EventB, SharedView, UpsertSharedView}; +use crate::common::a::{AggregateA, EventA}; +use crate::common::b::{AggregateB, EventB}; +use crate::common::shared::view::{SharedView, UpsertSharedView}; #[derive(Clone)] pub struct SharedEventHandler { diff --git a/examples/common/shared/mod.rs b/examples/common/shared/mod.rs index d57851f6..a6e90787 100644 --- a/examples/common/shared/mod.rs +++ b/examples/common/shared/mod.rs @@ -1,5 +1,2 @@ -pub use event_handler::*; -pub use view::*; - -mod event_handler; -mod view; +pub mod event_handler; +pub mod view; diff --git a/examples/common/shared/view.rs b/examples/common/shared/view.rs index 15d54113..ebd67a9c 100644 --- a/examples/common/shared/view.rs +++ b/examples/common/shared/view.rs @@ -1,7 +1,7 @@ use sqlx::{Executor, Pool, Postgres}; use uuid::Uuid; -use crate::common::random_letters; +use crate::common::util::random_letters; #[derive(Clone)] pub struct SharedView { diff --git a/examples/event_bus/main.rs b/examples/event_bus/main.rs index 16efe1aa..d6786651 100644 --- a/examples/event_bus/main.rs +++ b/examples/event_bus/main.rs @@ -20,7 +20,10 @@ use esrs::manager::AggregateManager; use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::AggregateState; -use crate::common::{new_pool, random_letters, BasicAggregate, BasicCommand, BasicError, BasicEventHandler, BasicView}; +use crate::common::basic::event_handler::BasicEventHandler; +use crate::common::basic::view::BasicView; +use crate::common::basic::{BasicAggregate, BasicCommand, BasicError}; +use crate::common::util::{new_pool, random_letters}; use crate::kafka::KafkaEventBusConsumer; use crate::rabbit::RabbitEventBusConsumer; diff --git a/examples/event_bus/rabbit.rs b/examples/event_bus/rabbit.rs index 84bf8687..aa7c75da 100644 --- a/examples/event_bus/rabbit.rs +++ b/examples/event_bus/rabbit.rs @@ -8,7 +8,7 @@ use esrs::handler::EventHandler; use esrs::store::StoreEvent; use esrs::Aggregate; -use crate::common::random_letters; +use crate::common::util::random_letters; pub struct RabbitEventBusConsumer { consumer: Consumer, diff --git a/examples/eventual_view/main.rs b/examples/eventual_view/main.rs index 3562ca96..ee592b4c 100644 --- a/examples/eventual_view/main.rs +++ b/examples/eventual_view/main.rs @@ -9,7 +9,10 @@ use esrs::manager::AggregateManager; use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::AggregateState; -use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicError, BasicEventHandler, BasicView}; +use crate::common::basic::event_handler::BasicEventHandler; +use crate::common::basic::view::BasicView; +use crate::common::basic::{BasicAggregate, BasicCommand, BasicError}; +use crate::common::util::new_pool; #[path = "../common/lib.rs"] mod common; diff --git a/examples/locking_strategies/main.rs b/examples/locking_strategies/main.rs index 76eaf40b..6a35ec43 100644 --- a/examples/locking_strategies/main.rs +++ b/examples/locking_strategies/main.rs @@ -45,7 +45,8 @@ use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::store::EventStore; use esrs::AggregateState; -use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicError, BasicEvent}; +use crate::common::basic::{BasicAggregate, BasicCommand, BasicError, BasicEvent}; +use crate::common::util::new_pool; #[path = "../common/lib.rs"] mod common; diff --git a/examples/multi_aggregate_rebuild/main.rs b/examples/multi_aggregate_rebuild/main.rs index f1ec0a61..40cc6b85 100644 --- a/examples/multi_aggregate_rebuild/main.rs +++ b/examples/multi_aggregate_rebuild/main.rs @@ -21,9 +21,12 @@ use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::store::StoreEvent; use esrs::AggregateState; -use crate::common::{ - new_pool, AggregateA, AggregateB, CommandA, CommandB, CommonError, EventA, EventB, SharedEventHandler, SharedView, -}; +use crate::common::a::{AggregateA, CommandA, EventA}; +use crate::common::b::{AggregateB, CommandB, EventB}; +use crate::common::shared::event_handler::SharedEventHandler; +use crate::common::shared::view::SharedView; +use crate::common::util::new_pool; +use crate::common::CommonError; use crate::transactional_event_handler::SharedTransactionalEventHandler; #[path = "../common/lib.rs"] diff --git a/examples/multi_aggregate_rebuild/transactional_event_handler.rs b/examples/multi_aggregate_rebuild/transactional_event_handler.rs index 0d9376d4..d6d2c449 100644 --- a/examples/multi_aggregate_rebuild/transactional_event_handler.rs +++ b/examples/multi_aggregate_rebuild/transactional_event_handler.rs @@ -5,7 +5,9 @@ use esrs::handler::TransactionalEventHandler; use esrs::store::postgres::PgStoreError; use esrs::store::StoreEvent; -use crate::common::{AggregateA, AggregateB, EventA, EventB, SharedView, UpsertSharedView}; +use crate::common::a::{AggregateA, EventA}; +use crate::common::b::{AggregateB, EventB}; +use crate::common::shared::view::{SharedView, UpsertSharedView}; #[derive(Clone)] pub struct SharedTransactionalEventHandler { diff --git a/examples/readme/main.rs b/examples/readme/main.rs index 4bf483c9..62e2c007 100644 --- a/examples/readme/main.rs +++ b/examples/readme/main.rs @@ -1,17 +1,15 @@ -use sqlx::{PgConnection, Pool, Postgres}; - use serde::{Deserialize, Serialize}; +use sqlx::{PgConnection, Pool, Postgres}; +use thiserror::Error; +use esrs::bus::EventBus; use esrs::handler::{EventHandler, TransactionalEventHandler}; use esrs::manager::AggregateManager; use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::store::StoreEvent; use esrs::Aggregate; -use esrs::bus::EventBus; -use thiserror::Error; - -use crate::common::new_pool; +use crate::common::util::new_pool; #[path = "../common/lib.rs"] mod common; diff --git a/examples/rebuilder/event_handler.rs b/examples/rebuilder/event_handler.rs index e91ed6a7..0948824c 100644 --- a/examples/rebuilder/event_handler.rs +++ b/examples/rebuilder/event_handler.rs @@ -4,11 +4,12 @@ use sqlx::{Pool, Postgres}; use esrs::handler::{EventHandler, ReplayableEventHandler}; use esrs::store::StoreEvent; +use crate::common::basic::view::BasicView; +use crate::common::basic::{BasicAggregate, BasicEvent}; + /// This is just an example. The need of v1 and v2 is due to having both the version of this event /// handler compiled in the code. In user codebase there will be only one `BasicEventHandler` /// got modified. -use crate::common::{BasicAggregate, BasicEvent, BasicView}; - #[derive(Clone)] pub struct BasicEventHandlerV1 { pub pool: Pool, diff --git a/examples/rebuilder/main.rs b/examples/rebuilder/main.rs index a248c395..2a6f5e84 100644 --- a/examples/rebuilder/main.rs +++ b/examples/rebuilder/main.rs @@ -40,7 +40,9 @@ use esrs::rebuilder::{PgRebuilder, Rebuilder}; use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::AggregateState; -use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicError, BasicView}; +use crate::common::basic::view::BasicView; +use crate::common::basic::{BasicAggregate, BasicCommand, BasicError}; +use crate::common::util::new_pool; use crate::event_handler::{AnotherEventHandler, BasicEventHandlerV1, BasicEventHandlerV2}; use crate::transactional_event_handler::{BasicTransactionalEventHandlerV1, BasicTransactionalEventHandlerV2}; diff --git a/examples/rebuilder/transactional_event_handler.rs b/examples/rebuilder/transactional_event_handler.rs index aa5e2b52..99b2bc3d 100644 --- a/examples/rebuilder/transactional_event_handler.rs +++ b/examples/rebuilder/transactional_event_handler.rs @@ -5,7 +5,8 @@ use esrs::handler::TransactionalEventHandler; use esrs::store::postgres::PgStoreError; use esrs::store::StoreEvent; -use crate::common::{BasicAggregate, BasicEvent, BasicView}; +use crate::common::basic::view::BasicView; +use crate::common::basic::{BasicAggregate, BasicEvent}; /// The `BasicTransactionalEventHandlerV1` and `BasicTransactionalEventHandlerV1` exists in this /// example just for the sake of showing how a single transactional event handler, in this case called diff --git a/examples/saga/main.rs b/examples/saga/main.rs index a72791fc..bee70405 100644 --- a/examples/saga/main.rs +++ b/examples/saga/main.rs @@ -17,7 +17,8 @@ use esrs::store::EventStore; use esrs::AggregateState; use crate::aggregate::{SagaAggregate, SagaCommand, SagaEvent}; -use crate::common::{new_pool, CommonError}; +use crate::common::util::new_pool; +use crate::common::CommonError; use crate::event_handler::SagaEventHandler; mod aggregate; diff --git a/examples/shared_view/main.rs b/examples/shared_view/main.rs index d960b3ef..1eda50ef 100644 --- a/examples/shared_view/main.rs +++ b/examples/shared_view/main.rs @@ -7,9 +7,12 @@ use esrs::manager::AggregateManager; use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::AggregateState; -use crate::common::{ - new_pool, AggregateA, AggregateB, CommandA, CommandB, CommonError, SharedEventHandler, SharedView, -}; +use crate::common::a::{AggregateA, CommandA}; +use crate::common::b::{AggregateB, CommandB}; +use crate::common::shared::event_handler::SharedEventHandler; +use crate::common::shared::view::SharedView; +use crate::common::util::new_pool; +use crate::common::CommonError; #[path = "../common/lib.rs"] mod common; diff --git a/examples/store_crud/main.rs b/examples/store_crud/main.rs index a12ae429..9fcf05af 100644 --- a/examples/store_crud/main.rs +++ b/examples/store_crud/main.rs @@ -40,7 +40,8 @@ use esrs::store::postgres::{PgStore, PgStoreBuilder}; use esrs::store::{EventStore, StoreEvent}; use esrs::AggregateState; -use crate::common::{new_pool, BasicAggregate, BasicEvent}; +use crate::common::basic::{BasicAggregate, BasicEvent}; +use crate::common::util::new_pool; #[path = "../common/lib.rs"] mod common; diff --git a/examples/transactional_view/main.rs b/examples/transactional_view/main.rs index 537d857f..d625ae2b 100644 --- a/examples/transactional_view/main.rs +++ b/examples/transactional_view/main.rs @@ -22,7 +22,9 @@ use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError}; use esrs::store::EventStore; use esrs::AggregateState; -use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicError, BasicView, BasicViewRow}; +use crate::common::basic::view::{BasicView, BasicViewRow}; +use crate::common::basic::{BasicAggregate, BasicCommand, BasicError}; +use crate::common::util::new_pool; use crate::transactional_event_handler::BasicTransactionalEventHandler; #[path = "../common/lib.rs"] diff --git a/examples/transactional_view/transactional_event_handler.rs b/examples/transactional_view/transactional_event_handler.rs index 1b3203f7..921eeae1 100644 --- a/examples/transactional_view/transactional_event_handler.rs +++ b/examples/transactional_view/transactional_event_handler.rs @@ -5,7 +5,8 @@ use esrs::handler::TransactionalEventHandler; use esrs::store::postgres::PgStoreError; use esrs::store::StoreEvent; -use crate::common::{BasicAggregate, BasicEvent, BasicView}; +use crate::common::basic::view::BasicView; +use crate::common::basic::{BasicAggregate, BasicEvent}; pub struct BasicTransactionalEventHandler { pub view: BasicView,