{"id":16193051,"url":"https://github.com/slashdotdash/eventstore-migrator","last_synced_at":"2025-07-09T15:31:32.943Z","repository":{"id":66695219,"uuid":"78343314","full_name":"slashdotdash/eventstore-migrator","owner":"slashdotdash","description":"Copy \u0026 transform migration strategy for Elixir EventStore","archived":false,"fork":false,"pushed_at":"2017-01-13T11:48:01.000Z","size":27,"stargazers_count":31,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-28T15:17:55.042Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slashdotdash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-08T13:07:53.000Z","updated_at":"2024-07-16T13:11:56.000Z","dependencies_parsed_at":"2023-03-11T00:14:44.334Z","dependency_job_id":null,"html_url":"https://github.com/slashdotdash/eventstore-migrator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slashdotdash%2Feventstore-migrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slashdotdash%2Feventstore-migrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slashdotdash%2Feventstore-migrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slashdotdash%2Feventstore-migrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slashdotdash","download_url":"https://codeload.github.com/slashdotdash/eventstore-migrator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243968440,"owners_count":20376397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T08:13:52.851Z","updated_at":"2025-03-19T04:30:35.856Z","avatar_url":"https://github.com/slashdotdash.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EventStore migrator\n\nCopy \u0026 transform migration strategy for [eventstore](https://github.com/slashdotdash/eventstore).\n\n\u003e Copy and transformation transforms every event to a new store. In this technique the old event store stays intact, and a new store is created instead.\n\n## Usage\n\n`EventStore.Migrator` copies an [event store](https://github.com/slashdotdash/eventstore) PostgreSQL database from a source to a target.\n\nIt allows you to modify the events during the copy. You can transform, remove, aggregate, and alter the serialization format of the events.\n\nThe migrator exposes a single `migrate` function. It expects an anonymous function that receives an event stream. You can use any of the functions from Elixir's [stream](https://hexdocs.pm/elixir/Stream.html) module to mutate the event stream. The modified events are appended to the target event store database.\n\n### Remove an unwanted event\n\n```elixir\nEventStore.Migrator.migrate(fn stream -\u003e\n  Stream.reject(\n    stream,\n    fn (event_data) -\u003e event_data.event_type == \"UnwantedEvent\" end\n  )\nend)\n```\n\n### Upgrade an event\n\n```elixir\ndefmodule OriginalEvent, do: defstruct [uuid: nil]\ndefmodule UpgradedEvent, do: defstruct [uuid: nil, additional: nil]\n\nEventStore.Migrator.migrate(fn stream -\u003e\n  Stream.map(\n    stream,\n    fn (event) -\u003e\n      case event.data do\n        %OriginalEvent{uuid: uuid} -\u003e\n          %EventStore.RecordedEvent{event |\n            event_type: \"UpgradedEvent\",\n            data: %UpgradedEvent{uuid: uuid, additional: \"upgraded #{uuid}\"},\n          }\n        _ -\u003e event\n      end\n    end\n  )\nend)\n```\n\n### Aggregate multiple events into one event\n\n```elixir\ndefmodule SingleEvent, do: defstruct [uuid: nil, group: nil]\ndefmodule AggregatedEvent, do: defstruct [uuids: [], group: nil]\n\n# aggregate multiple single events for the same group into one aggregated event\ndefp aggregate([%{data: %SingleEvent{}}] = events), do: events\ndefp aggregate([%{data: %SingleEvent{group: group}} = source | _] = events) do\n  [\n    %EventStore.RecordedEvent{source |\n      data: %AggregatedEvent{\n        uuids: Enum.map(events, fn event -\u003e event.data.uuid end),\n        group: group,\n      },\n      event_type: \"AggregatedEvent\",\n    },\n  ]\nend\ndefp aggregate(events), do: events\n\nEventStore.Migrator.migrate(fn stream -\u003e\n  stream\n  |\u003e Stream.chunk_by(fn event -\u003e {event.stream_id, event.event_type} end)\n  |\u003e Stream.map(fn events -\u003e aggregate(events) end)\n  |\u003e Stream.flat_map(fn events -\u003e events end)\nend)\n```\n\n### Migrate serialization format\n\nConfigure the source and target serializers in the environment configuration file (e.g. `config/dev.exs`).\n\n```elixir\nconfig :eventstore, EventStore.Storage,\n  serializer: JsonSerializer,\n  # ...\n\nconfig :eventstore_migrator, EventStore.Migrator,\n  serializer: AlternateSerializer,\n  # ...\n```\n\nRun the migration without changing the event stream.\n\n```elixir\nEventStore.Migrator.migrate(source_config, target_config, fn stream -\u003e stream end)\n```\n\n### Remarks\n\nStreams are composable so you can combine multiple transforms in a single migration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslashdotdash%2Feventstore-migrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslashdotdash%2Feventstore-migrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslashdotdash%2Feventstore-migrator/lists"}