Skip to content

Commit d441675

Browse files
authored
Merge pull request #305 from quarterpi/master
Add documentation for deleting streams
2 parents cad2dbe + 494133e commit d441675

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ MIT License
3838
- [Reading from all streams](guides/Usage.md#reading-from-all-streams)
3939
- [Stream from all streams](guides/Usage.md#stream-from-all-streams)
4040
- [Linking events between streams](guides/Usage.md#linking-events-between-streams)
41+
- [Deleting streams](guides/Usage.md#deleting-streams)
4142
- [Subscriptions](guides/Subscriptions.md)
4243
- [Transient subscriptions](guides/Subscriptions.md#transient-subscriptions)
4344
- [Persistent subscriptions](guides/Subscriptions.md#persistent-subscriptions)

guides/Usage.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,64 @@ alias MyApp.EventStore
156156
```
157157

158158
You can also pass a list of `event_ids` instead of recorded event structs to link events.
159+
160+
## Deleting streams
161+
162+
There are two ways to delete streams. Soft delete and Hard delete.
163+
164+
Use soft delete when you no longer care about a streams events, but want to preserve the full history of events.
165+
166+
Use hard delete when you want a stream to go away more than a bad case of viral gastroenteritis (for example GDPR compliance).
167+
168+
### Soft delete
169+
170+
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.
171+
172+
A soft deleted stream cannot be read nor appended to. Subscriptions to the deleted stream will not receive any events but subscriptions containing linked events from the deleted stream, such as the global all events stream, will still receive events from the deleted stream.
173+
174+
#### Examples
175+
176+
Delete a stream at any version:
177+
```elixir
178+
:ok = MyApp.EventStore.delete_stream("stream1", :any_version, :soft)
179+
```
180+
181+
Delete a stream at an expected version:
182+
```elixir
183+
:ok = MyApp.EventStore.delete_stream("stream2", 3, :soft)
184+
```
185+
186+
Delete stream will use soft delete by default so you can omit the type:
187+
```elixir
188+
:ok = MyApp.EventStore.delete_stream("stream1", :any_version)
189+
```
190+
191+
### Hard delete
192+
193+
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 ($all) stream and any linked streams.
194+
195+
After being hard deleted, a stream can later be appended to and read as if had never existed.
196+
197+
#### Examples
198+
199+
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:
200+
```elixir
201+
defmodule MyApp.EventStore do
202+
use EventStore, otp_app: :my_app, enable_hard_deletes: true
203+
end
204+
```
205+
206+
Or via config:
207+
```elixir
208+
config :my_app, MyApp.EventStore, enable_hard_deletes: true
209+
```
210+
211+
Hard delete a stream at any version:
212+
```elixir
213+
:ok = MyApp.EventStore.delete_stream("stream1", :any_version, :hard)
214+
```
215+
216+
Hard delete a stream that should exist:
217+
```elixir
218+
:ok = MyApp.EventStore.delete_stream("stream2", :stream_exists, :hard)
219+
```

0 commit comments

Comments
 (0)