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

Support Postgres schemas #182

Merged
merged 8 commits into from
Dec 5, 2019
Merged

Support Postgres schemas #182

merged 8 commits into from
Dec 5, 2019

Conversation

slashdotdash
Copy link
Member

Allow an event store to specify a Postgres schema. By default the public schema will be used.

defmodule MyApp.EventStore do
  use EventStore, otp_app: :my_app, schema: "example"
end

Or define it in environment config when configuring the database connection settings:

# config/config.exs
config :my_app, MyApp.EventStore, schema: "example"

This feature allows you to define and start multiple event stores sharing a single Postgres database, but with their data isolated and segregated by schema.

Note the mix event_store.<task> tasks to create, initialize, and drop an event store database will also handle creating and/or dropping the schema.

Use `after_connect` to set the Postgres connection `search_path` to the event store schema. This will force all queries to use the schema, without requiring any alteration of the SQL statements.
Event notifications should be restricted to only those from the event store's schema.
The namespace key is derived from the unique `oid` value for the `subscriptions` table. The `oid` is unique within a database and differs for identically named tables defined in different schemas and on repeat table definitions.

This change aims to prevent lock collision with application level advisory lock usage and other libraries using Postgres advisory locks. Now there is a 1 in 2,147,483,647 chance of colliding with other locks.
@slashdotdash slashdotdash merged commit 8b71fdc into master Dec 5, 2019
@slashdotdash slashdotdash deleted the feature/schema branch December 5, 2019 16:07
slashdotdash added a commit that referenced this pull request Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant