{"id":15010152,"url":"https://github.com/beardedeagle/mnesiac","last_synced_at":"2025-04-05T12:06:14.780Z","repository":{"id":45566170,"uuid":"141378316","full_name":"beardedeagle/mnesiac","owner":"beardedeagle","description":"Mnesia autoclustering made easy!","archived":false,"fork":false,"pushed_at":"2023-06-08T10:57:46.000Z","size":134,"stargazers_count":134,"open_issues_count":8,"forks_count":21,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T11:08:08.730Z","etag":null,"topics":["clustering","distributed","elixir","erlang","mnesia","otp","replication"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beardedeagle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null},"funding":{"patreon":"beardedeagle","custom":["paypal.me/beardedeagle87"]}},"created_at":"2018-07-18T03:51:54.000Z","updated_at":"2025-03-29T06:38:13.000Z","dependencies_parsed_at":"2022-09-10T17:10:50.139Z","dependency_job_id":"e2dde578-0fb2-42ee-9fe9-346eea9e7e14","html_url":"https://github.com/beardedeagle/mnesiac","commit_stats":{"total_commits":89,"total_committers":5,"mean_commits":17.8,"dds":0.1348314606741573,"last_synced_commit":"c404e985194ea0ac360579d97cd371c6ae901011"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardedeagle%2Fmnesiac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardedeagle%2Fmnesiac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardedeagle%2Fmnesiac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beardedeagle%2Fmnesiac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beardedeagle","download_url":"https://codeload.github.com/beardedeagle/mnesiac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332604,"owners_count":20921853,"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":["clustering","distributed","elixir","erlang","mnesia","otp","replication"],"created_at":"2024-09-24T19:30:56.875Z","updated_at":"2025-04-05T12:06:14.755Z","avatar_url":"https://github.com/beardedeagle.png","language":"Elixir","funding_links":["https://patreon.com/beardedeagle","paypal.me/beardedeagle87"],"categories":[],"sub_categories":[],"readme":"# Mnesiac\n\n[![CI](https://github.com/beardedeagle/mnesiac/actions/workflows/ci.yml/badge.svg)](https://github.com/beardedeagle/mnesiac/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/beardedeagle/mnesiac/badge.svg?branch=master)](https://coveralls.io/github/beardedeagle/mnesiac?branch=master) [![Hex.pm](http://img.shields.io/hexpm/v/mnesiac.svg?style=flat)](https://hex.pm/packages/mnesiac) [![Hex.pm downloads](https://img.shields.io/hexpm/dt/mnesiac.svg?style=flat)](https://hex.pm/packages/mnesiac)\n\nMnesia auto clustering made easy!\n\nDocs can be found at [https://hexdocs.pm/mnesiac](https://hexdocs.pm/mnesiac).\n\n**_NOTICE:_** Mnesiac, while stable, is still considered pre `1.0`. This means the API can, and may, change at any time. Please ensure you review the docs and changelog prior to updating, or pin the version of mnesiac you are using in your `mix.exs` if necessary.\n\n**_NOTICE:_** Mnesiac allows a significant amount of freedom with how it behaves. This allows you to customize Mnesiac to suit your needs. However, this also allows for a fair amount of foot gunning. Please ensure you've done your due diligence when using this library, or Mnesia itself for that matter. It isn't a silver bullet, and it shouldn't be treated as one.\n\n## Installation\n\nSimply add `mnesiac` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:mnesiac, \"~\u003e 0.3\"}\n  ]\nend\n```\n\nEdit your app's config.exs to add the list of Mnesia stores:\n\n```elixir\nconfig :mnesiac,\n  stores: [MyApp.ExampleStore, ...],\n  schema_type: :disc_copies, # defaults to :ram_copies\n  table_load_timeout: 600_000 # milliseconds, default is 600_000\n```\n\nThen add `mnesiac` to your supervision tree:\n\n- **_EXAMPLE:_** With `libcluster` using the `Cluster.Strategy.Epmd` strategy:\n\n```elixir\n  ...\n\n    topology = Application.get_env(:libcluster, :topologies)\n    hosts = topology[:myapp][:config][:hosts]\n\n    children = [\n      {Cluster.Supervisor, [topology, [name: MyApp.ClusterSupervisor]]},\n      {Mnesiac.Supervisor, [hosts, [name: MyApp.MnesiacSupervisor]]},\n      ...\n    ]\n\n  ...\n```\n\n- **_EXAMPLE:_** Without `libcluster`:\n\n```elixir\n  ...\n\n    children = [\n      {\n        Mnesiac.Supervisor,\n        [\n          [:\"test01@127.0.0.1\", :\"test02@127.0.0.1\"],\n          [name: MyApp.MnesiacSupervisor]\n        ]\n      },\n      ...\n    ]\n\n  ...\n```\n\n## Usage\n\n### Table creation\n\nCreate a table store, `use Mnesiac.Store`, and add it to your app's config.exs.\n\nAll stores **_MUST_** implement its own `store_options/0`, which returns a keyword list of store options.\n\nThere are three optional callbacks which can be implemented:\n\n- `init_store/0`, which allows users to implement custom store initialization logic. Triggered by Mnesiac.\n- `copy_store/0`, which allows users to implement a custom call to copy a store. Triggered by Mnesiac.\n- `resolve_conflict/1`, which allows a user to implement logic when Mnesiac detects a store with records on both the local and remote Mnesia cluster node. Triggered by Mnesiac. Default is to do nothing.\n\n**_MINIMAL EXAMPLE:_**\n\n```elixir\ndefmodule MyApp.ExampleStore do\n  @moduledoc \"\"\"\n  Provides the structure of ExampleStore records for a minimal example of Mnesiac.\n  \"\"\"\n  use Mnesiac.Store\n  import Record, only: [defrecord: 3]\n\n  @doc \"\"\"\n  Record definition for ExampleStore example record.\n  \"\"\"\n  defrecord(\n    :example,\n    __MODULE__,\n    id: nil,\n    topic_id: nil,\n    event: nil\n  )\n\n  @typedoc \"\"\"\n  ExampleStore example record field type definitions.\n  \"\"\"\n  @type example ::\n          record(\n            :example,\n            id: String.t(),\n            topic_id: String.t(),\n            event: String.t()\n          )\n\n  @impl true\n  def store_options,\n    do: [\n      record_name: :example,\n      attributes: example() |\u003e example() |\u003e Keyword.keys(),\n      index: [:topic_id],\n      ram_copies: [node()]\n    ]\nend\n```\n\n### Clustering\n\nIf you are using `libcluster` or another clustering library, ensure that the clustering library starts before `mnesiac`. That's all, you don't need to do anything else.\n\nIf you are not using `libcluster` or similar clustering libraries then:\n\n- When a node joins to an erlang/elixir cluster, run the `Mnesiac.init_mnesia/1` function on the **_new node_**. This will initialize and copy the store contents from the other online nodes in the Mnesia cluster.\n\n## Development\n\nEnsure you have the proper language versions installed. To do this, an `asdf` tools file has been provided. Run the following:\n\n```shell\ngit clone https://github.com/beardedeagle/mnesiac.git\ngit checkout -b MyFeature\nasdf install\nmix local.hex --force\nmix local.rebar --force\nmix deps.get --force\nmix deps.compile --force\nmix compile --force\n```\n\n**_NOTICE:_** You can find the `asdf` tool [here][1].\n\n## Testing\n\nBefore you run any tests, ensure that you have cleaned up Mnesia:\n\n```shell\nmix purge.db\n```\n\nTest results and coverage reports are generated by running the following:\n\n```shell\nmix coveralls.html --trace --slowest 10 --no-start\n```\n\n## Notice\n\nThis library was built standing on the shoulders of giants. A big thanks goes out to Mustafa Turan. The original library this was forked from can be found here: \u003chttps://github.com/mustafaturan/mnesiam\u003e.\n\nHappy coding!\n\n[1]: https://github.com/asdf-vm/asdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeardedeagle%2Fmnesiac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeardedeagle%2Fmnesiac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeardedeagle%2Fmnesiac/lists"}