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

Delete event stream #203

Merged
merged 2 commits into from
May 13, 2020
Merged

Delete event stream #203

merged 2 commits into from
May 13, 2020

Conversation

slashdotdash
Copy link
Member

@slashdotdash slashdotdash commented May 7, 2020

Allow soft or hard deletion of an event stream.

Soft delete

Will mark the stream as deleted, but will not delete its events. Events from soft deleted streams will still appear in the globally ordered all events ($all) stream and in any linked streams.

A soft deleted stream cannot be read nor appended to. Subscriptions to the deleted stream will not receive any events.

Hard delete

Will permanently delete the stream and its events. This is irreversible and will remove data. Events will be removed from the globally ordered all events stream and any linked streams.

After being hard deleted, a stream can later be appended to and read as if had never existed.

Examples

Soft delete a stream

Delete a stream at any version:

:ok = MyApp.EventStore.delete_stream("stream1", :any_version, :soft)

Delete a stream at an expected version:

:ok = MyApp.EventStore.delete_stream("stream2", 3, :soft)

Delete stream will use soft delete by default so you can omit the type:

:ok = MyApp.EventStore.delete_stream("stream1", :any_version)

Hard delete a stream

Since hard deletes are destructive and irreversible they are disabled by default. To use hard deletes you must first enable them for the event store:

defmodule MyApp.EventStore do
  use EventStore, otp_app: :my_app, enable_hard_deletes: true
end

Or via config:

config :my_app, MyApp.EventStore, enable_hard_deletes: true

Hard delete a stream:

:ok = MyApp.EventStore.delete_stream("stream2", :stream_exists, :hard)

Fixes #170.

@slashdotdash slashdotdash marked this pull request as draft May 7, 2020 15:44
@slashdotdash slashdotdash self-assigned this May 7, 2020
@slashdotdash slashdotdash force-pushed the feature/delete-stream branch 4 times, most recently from 9ca6687 to 2cbf64e Compare May 11, 2020 15:33
- Soft delete event stream.
- Hard delete event stream.
- Subscriptions to a deleted stream won't receive any events.
- Ensure events are not deleted from other streams
- Use Postgres triggers to allow/prevent UPDATE and DELETE to events, streams, and stream_events tables.
- Use EventStore and Postgres run-time configuration parameter to enable hard deletes.
- Add v1.2 schema migration and test.
@slashdotdash slashdotdash force-pushed the feature/delete-stream branch from 2cbf64e to 4caa07f Compare May 13, 2020 09:33
@slashdotdash slashdotdash marked this pull request as ready for review May 13, 2020 09:34
@slashdotdash slashdotdash merged commit 1617798 into master May 13, 2020
@slashdotdash slashdotdash deleted the feature/delete-stream branch May 13, 2020 10:45
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.

Event stream deletion
1 participant