{"id":16389454,"url":"https://github.com/qqwy/elixir-revisionair_ecto","last_synced_at":"2025-12-11T23:47:00.547Z","repository":{"id":48289962,"uuid":"89267678","full_name":"Qqwy/elixir-revisionair_ecto","owner":"Qqwy","description":"  A Revisionair adapter based on Ecto. Allows you to persist and keep track of revisions of your data structures in any of Ecto's supported databases.","archived":false,"fork":false,"pushed_at":"2021-08-03T05:18:57.000Z","size":71,"stargazers_count":18,"open_issues_count":7,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-03-15T03:35:02.900Z","etag":null,"topics":["ecto","elixir-lang","elixir-library","revision"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/revisionair_ecto","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/Qqwy.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}},"created_at":"2017-04-24T17:21:41.000Z","updated_at":"2023-03-04T14:52:17.000Z","dependencies_parsed_at":"2022-07-22T22:02:12.611Z","dependency_job_id":null,"html_url":"https://github.com/Qqwy/elixir-revisionair_ecto","commit_stats":null,"previous_names":["qqwy/elixir_revisionair_ecto"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qqwy%2Felixir-revisionair_ecto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qqwy%2Felixir-revisionair_ecto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qqwy%2Felixir-revisionair_ecto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qqwy%2Felixir-revisionair_ecto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qqwy","download_url":"https://codeload.github.com/Qqwy/elixir-revisionair_ecto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245056889,"owners_count":20553855,"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":["ecto","elixir-lang","elixir-library","revision"],"created_at":"2024-10-11T04:33:05.817Z","updated_at":"2025-12-11T23:47:00.508Z","avatar_url":"https://github.com/Qqwy.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RevisionairEcto\n\n[![Hex.pm](https://img.shields.io/hexpm/v/revisionair_ecto.svg)](https://hex.pm/packages/revisionair_ecto)\n\n\nA [Revisionair](https://github.com/Qqwy/elixir_revisionair) adapter based on [Ecto](https://github.com/elixir-ecto/ecto). Allows you to persist and keep track of revisions of your data structures in any of Ecto's supported databases.\n\nThe things that you want to keep track of do _not_ necessarily need to be (Ecto-backed) models/schemas. _Any_ data structure can be used (even things that are not structs).\n\n## Installation\n\nFirst, install the library by adding `revisionair_ecto` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:revisionair_ecto, \"~\u003e 1.0\"}]\nend\n```\n\nThen, create a migration (`mix ecto.gen.migration revisions_table`) akin to the following:\n\n```elixir\n\ndefmodule RevisionairEcto.Repo.Migrations.RevisionsTable do\n  use Ecto.Migration\n\n  def change do\n    create table(:revisions, primary_key: false) do\n      add :item_type, :string, null: false\n      # If you want to use UUIDs instead, alter the following line to\n      # add :item_id, :uuid, null: false\n      add :item_id, :integer, null: false\n      # If you want to use JSON serialization instead, alter the following line to\n      # add :encoded_item, :json, null: false\n      add :encoded_item, :binary, null: false\n      add :metadata, :map, null: false\n      add :revision, :integer, null: false\n    end\n\n    create unique_index(:revisions, [:item_type, :item_id, :revision])\n  end\nend\n```\n\nFinally, in your `config/config.exs`, add the following lines to configure Revisonair and RevisionairEcto:\n\n\n```elixir\n# Set default Revisionair storage adapter.\nconfig :revisionair, storage: RevisionairEcto\n\n# Default repo used by RevisionairEcto:\nconfig :revisionair_ecto, repo: RevisionairEcto.Repo\n\n# Uncomment if you use UUIDs instead of numerical ids:\n# config :revisionair_ecto, item_id_type: :uuid\n\n# Uncomment if you use JSON serialization instead of binary term storage:\n# config :revisionair_ecto, serialization_format: :json\n\n# Uncomment if you use a different table than \"revisions\" to store the revisions information:\n# config :revisionair_ecto, revisions_table: \"table_name\"\n```\n\nOf course, any of these settings can also be specified in the `options` parameter when calling any of the Revisionair functions:\n\n```elixir\n\nRevisionair.store_revision(my_post, [storage: RevisionairEcto, storage_options: [repo: MyOtherRepo, revisions_table: \"my_revisions\", item_id_type: :uuid, serialization_format: :json]])\n\n```\n\n(This also allows overriding certain settings only in certain special locations.)\n\n## Usage\n\nThe functions in this module should not be used directly, rather, the functions that the [Revisionair](https://github.com/Qqwy/elixir_revisionair) module exposes should be used.\n\nAs these function calls will hit the database directly, make sure that especially `store_revision` is used within a Repo transaction to ensure that the revision is only stored if the other database operations could be performed successfully.\n\nExample: \n```elixir\n\n{:ok, post} = Repo.transaction fn -\u003e\n  post = Repo.insert!(%Post{title: \"Test\", content: \"Lorem ipsum\"})\n  \n  :ok = Revisionair.store_revision(post, Post, post.id)\n  \n  # if using JSON serialization, you must also pass a whitelist of attributes you wish to serialize:\n  # :ok = Revisionair.store_revision(post, Post, post.id, [storage_options: [attributes: [:id, :content, :title]]])\n\n  post\nend\n\nRevisionair.newest_revision(post)\nRevisionair.list_revisions(post)\nRevisionair.get_revision(post, 0)\n```\n\n\n## Changelog\n\n- 1.2.2 Removes unused `struct_name` column from migration examples.\n- 1.2.1 Updates migration examples (in README and tests) to no longer include unneccesary primary key and superfluous index.\n- 1.2.0 Adds the possibility to serialize data using a JSON format instead of the Erlang Term Format.\n- 1.1.0 Upgrade to Ecto 3.\n- 1.0.2 Removes superfluous and noisy logging call.\n- 1.0.1 Updates Revisionair version.\n- 1.0.0 First Stable Version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqqwy%2Felixir-revisionair_ecto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqqwy%2Felixir-revisionair_ecto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqqwy%2Felixir-revisionair_ecto/lists"}