From 9cbd2fa457a53dcbc9aa3838294654807d5508e5 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Wed, 19 Nov 2025 00:15:52 -0500 Subject: [PATCH] chore!: remove deprecated project macros in Ecto projections Signed-off-by: Yordis Prieto --- guides/explanations/fork-differences.md | 23 ++---- lib/commanded/projections/ecto.ex | 30 -------- .../deprecated_projection_test.exs | 72 ------------------- 3 files changed, 7 insertions(+), 118 deletions(-) delete mode 100644 test/projections/deprecated_projection_test.exs diff --git a/guides/explanations/fork-differences.md b/guides/explanations/fork-differences.md index ffadd400..f88c0634 100644 --- a/guides/explanations/fork-differences.md +++ b/guides/explanations/fork-differences.md @@ -13,6 +13,13 @@ This fork maintains an independent release cycle to introduce new features and i ## Breaking Changes ❌ +### **Removed Deprecated Ecto Projections "do end" Block Syntax** + +**Changes:** +- Removed deprecated `project(event, do: block)` macro variant +- Removed deprecated `project(event, metadata, do: block)` macro variant +- Only function-based syntax is now supported: `project(event, fn multi -> ... end)` + ### **Removed ProcessManager Support** [PR #24](https://github.com/straw-hat-team/commanded/pull/24) @@ -24,8 +31,6 @@ This fork maintains an independent release cycle to introduce new features and i **Reason:** The saga pattern can be achieved using event handlers with read models and aggregates, eliminating the need for the additional ProcessManager abstraction. ---- - ### **Removed Upcasting Support** [PR #26](https://github.com/straw-hat-team/commanded/pull/26) @@ -36,8 +41,6 @@ This fork maintains an independent release cycle to introduce new features and i **Reason:** Event schema transformations can be handled explicitly in event handlers and aggregates using pattern matching, eliminating the need for a global upcasting component. ---- - ### **EnrichedMetadata Struct** [PR #11](https://github.com/straw-hat-team/commanded/pull/11) @@ -47,8 +50,6 @@ This fork maintains an independent release cycle to introduce new features and i **Breaking:** Event handler callbacks now receive `%EnrichedMetadata{}` instead of a plain map. ---- - ## Features Added ✨ ### **UUIDv7 Support** @@ -58,8 +59,6 @@ This fork maintains an independent release cycle to introduce new features and i - Added UUIDv7 generation support for command and event IDs - Modified command router to use `UUID.uuid7/0` by default ---- - ### **Configurable UUID Provider** **Changes:** @@ -67,8 +66,6 @@ This fork maintains an independent release cycle to introduce new features and i - Made UUID provider configurable - Simplified UUID module by delegating to Uniq ---- - ### **Aggregate Telemetry for Version Conflicts** [PR #8](https://github.com/straw-hat-team/commanded/pull/8) @@ -76,8 +73,6 @@ This fork maintains an independent release cycle to introduce new features and i - Added telemetry events for wrong expected version errors in aggregates - Enhanced monitoring capabilities for version conflicts ---- - ### **Custom Event ID Support** [PR #2](https://github.com/straw-hat-team/commanded/pull/2) @@ -86,8 +81,6 @@ This fork maintains an independent release cycle to introduce new features and i - Ability to set custom event IDs from event structs - Support for deterministic event IDs ---- - ### **EventStore Adapter** [PR #1](https://github.com/straw-hat-team/commanded/pull/1) @@ -95,8 +88,6 @@ This fork maintains an independent release cycle to introduce new features and i - Bundled `Commanded.EventStore.Adapters.EventStore` directly into Commanded - Eliminates need for separate `commanded_eventstore_adapter` package dependency ---- - ### **Ecto Projections Integration** **Changes:** diff --git a/lib/commanded/projections/ecto.ex b/lib/commanded/projections/ecto.ex index ea3206cb..6224e4d2 100644 --- a/lib/commanded/projections/ecto.ex +++ b/lib/commanded/projections/ecto.ex @@ -580,21 +580,6 @@ if Code.ensure_loaded?(Ecto) do end end - defmacro project(event, do: block) do - IO.warn( - "project macro with \"do end\" block is deprecated; use project/2 with function instead", - Macro.Env.stacktrace(__ENV__) - ) - - quote do - def handle(unquote(event) = event, metadata) do - update_projection(event, metadata, fn var!(multi) -> - unquote(block) - end) - end - end - end - @doc """ Project a domain event into a read model by appending one or more operations to the `Ecto.Multi` struct passed to the projection function you define @@ -617,21 +602,6 @@ if Code.ensure_loaded?(Ecto) do end end - defmacro project(event, metadata, do: block) do - IO.warn( - "project macro with \"do end\" block is deprecated; use project/3 with function instead", - Macro.Env.stacktrace(__ENV__) - ) - - quote do - def handle(unquote(event) = event, unquote(metadata) = metadata) do - update_projection(event, metadata, fn var!(multi) -> - unquote(block) - end) - end - end - end - @doc """ Project a domain event and its metadata map into a read model by appending one or more operations to the `Ecto.Multi` struct passed to the projection diff --git a/test/projections/deprecated_projection_test.exs b/test/projections/deprecated_projection_test.exs deleted file mode 100644 index 86ad8848..00000000 --- a/test/projections/deprecated_projection_test.exs +++ /dev/null @@ -1,72 +0,0 @@ -defmodule Commanded.Projections.DeprecatedProjectionTest do - use ExUnit.Case - - import Commanded.Projections.ProjectionAssertions - import ExUnit.CaptureIO - - alias Commanded.Projections.Events.AnEvent - alias Commanded.Projections.Projection - alias Commanded.Projections.Repo - alias Ecto.Adapters.SQL.Sandbox - - setup do - start_supervised!(TestApplication) - Sandbox.checkout(Repo) - end - - test "should handle a projected event" do - capture_io(:stderr, fn -> - defmodule DeprecatedProjector do - use Commanded.Projections.Ecto, - application: TestApplication, - name: "DeprecatedProjector", - repo: Commanded.Projections.Repo - - project %AnEvent{name: name}, _metadata do - Ecto.Multi.insert(multi, :my_projection, %Projection{name: name}) - end - end - - assert :ok == - DeprecatedProjector.handle(%AnEvent{}, %{ - handler_name: "DeprecatedProjector", - event_number: 1 - }) - - assert_projections(Projection, ["AnEvent"]) - assert_seen_event("DeprecatedProjector", 1) - end) - end - - test "should warn project/2 macro deprecated" do - assert capture_io(:stderr, fn -> - defmodule DeprecatedProjectorWarn2 do - use Commanded.Projections.Ecto, - application: TestApplication, - name: "DeprecatedProjectorWarn2", - repo: Commanded.Projections.Repo - - project %AnEvent{name: name} do - Ecto.Multi.insert(multi, :my_projection, %Projection{name: name}) - end - end - end) =~ - "project macro with \"do end\" block is deprecated; use project/2 with function instead" - end - - test "should warn project/3 macro deprecated" do - assert capture_io(:stderr, fn -> - defmodule DeprecatedProjectorWarn3 do - use Commanded.Projections.Ecto, - application: TestApplication, - name: "DeprecatedProjectorWarn3", - repo: Commanded.Projections.Repo - - project %AnEvent{name: name}, _metadata do - Ecto.Multi.insert(multi, :my_projection, %Projection{name: name}) - end - end - end) =~ - "project macro with \"do end\" block is deprecated; use project/3 with function instead" - end -end