feat: add Tempest quickstart examples and multi-tenant ORM fix#674
Open
dgafka wants to merge 2 commits into
Open
feat: add Tempest quickstart examples and multi-tenant ORM fix#674dgafka wants to merge 2 commits into
dgafka wants to merge 2 commits into
Conversation
Runnable Tempest + Ecotone examples: active-record model as aggregate, event-sourced projection read model, and multi-tenant message bus routing one aggregate to per-tenant databases (postgres + mysql) with #[MultiTenantConnection] assertions.
TempestTenantDatabaseSwitcher promoted the tenant DatabaseConfig via singleton(), but DatabaseConfig implements HasTag so the binding was silently re-tagged to the tenant slot, leaving the discovered (SQLite) default in place; DatabaseInitializer then rebuilt the default Connection from it and clobbered the promoted one. switchOn now builds a GenericDatabase from the shared tenant Connection and registers it as the untagged Database singleton, so aggregate save() follows the active tenant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why is this change proposed?
Ecotone's Tempest integration shipped without runnable examples, leaving new users without a concrete starting point. This adds three Docker-runnable quickstarts covering the core patterns (active-record model as aggregate, event-sourced projection, multi-tenant message bus). Building the multi-tenant example surfaced a real bug: a Tempest active-record aggregate did not follow the per-tenant connection switch —
IsDatabaseModel::save()wrote to Tempest's discovered default (SQLite) instead of the active tenant's database — so the fix ships alongside the examples that prove it.Description of Changes
Tempest/Model— a TempestIsDatabaseModelas an Ecotone#[Aggregate], exercised via Command/Query bus, a#[Repository]gateway, and a#[DbalQuery]read side.Tempest/Projection/DatabaseReadModel— an event-sourcedUseraggregate with a#[ProjectionV2]read model and projection lifecycle commands.Tempest/MultiTenant/MessageBus— oneCustomeraggregate routed to two engines (tenant_a→PostgreSQL, tenant_b→MySQL) by message header, asserting isolation via the native#[MultiTenantConnection]attribute.TempestTenantDatabaseSwitcher—switchOnnow registers aDatabasebuilt from the shared tenant connection as the untagged singleton, so aggregatesave()follows the active tenant (root cause:DatabaseConfig implements HasTag, so the previoussingleton(DatabaseConfig::class, …)was silently re-tagged and the SQLite default was rebuilt over the promoted connection).TenantAggregatePersistenceTestproving UUID-PK aggregate persistence isolates across postgres + mysql.Usage
Use cases
Flow
sequenceDiagram participant Client participant CommandBus participant Switcher as TempestTenantDatabaseSwitcher participant Customer as Customer (Aggregate) participant DB as Tenant DB (PG / MySQL) Client->>CommandBus: send(RegisterCustomer, metadata[tenant=tenant_a]) CommandBus->>Switcher: tenant activated, switchOn Switcher->>Switcher: promote tenant Connection + Database (untagged) CommandBus->>Customer: register() then save() Customer->>DB: INSERT into the active tenant's databasePull Request Contribution Terms