Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic schema prefix #28

Merged
merged 5 commits into from Dec 16, 2019
Merged

Dynamic schema prefix #28

merged 5 commits into from Dec 16, 2019

Conversation

slashdotdash
Copy link
Member

@slashdotdash slashdotdash commented Dec 16, 2019

Support dynamic schema prefix for the projection versions table which can determine the schema based upon the event being projected.

This pull request extends support for the schema_prefix config option to support a one-arity function as a projector option:

defmodule MyApp.ExampleProjector do
  use Commanded.Projections.Ecto,
    application: MyApp.Application,
    repo: MyApp.Projections.Repo,    
    name: "example_projection",
    schema_prefix: fn event -> "example_schema_prefix" end
end

The function will receive the event as the single argument allowing you to use the same or a different schema for each event.

Alternatively, you may now define a schema_prefix/1 callback function in the projector module:

defmodule MyApp.ExampleProjector do
  use Commanded.Projections.Ecto,
    application: MyApp.Application,
    name: "example_projection"

  @impl Commanded.Projections.Ecto
  def schema_prefix(event), do: "example_schema_prefix"
end

The function will receive the event as the single argument allowing you to use the same or a different schema for each event.

An example usage could be for tenant specific projections where each tenant's data is projected and stored in a separate database schema:

@impl Commanded.Projections.Ecto
def schema_prefix(%_{tenant: tenant}), do: tenant

Closes #27.

slashdotdash added a commit that referenced this pull request Dec 16, 2019
@slashdotdash slashdotdash merged commit db93d9a into master Dec 16, 2019
@slashdotdash slashdotdash deleted the feature/dynamic-schema-prefix branch December 16, 2019 16:09
@slashdotdash slashdotdash self-assigned this May 25, 2020
@slashdotdash slashdotdash mentioned this pull request Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic schema prefix
1 participant