README.md

# Verex

This is a simple versioning library for Phoenix. Rather than only versioning changes or
old inactive versions, this library allows for a full history of your modules. Verex does not use an independent
'versions' table, but incorporates the full history into the modules existing table. Verex makes use of
a `current_flag` in the repo to flag an entry as active. It also makes use of a `parent_id` to allow for simple traversing
of an entries history.
By keeping a full history, Verex allows for associations with other modules on 'un-active' records.

## Installation

This package is [available in Hex](https://hex.pm/packages/verex), the package can be installed
by adding `verex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [{:verex, "~> 0.2.0"}]
end
```

## Configuration

Verex makes use of the repo by modifying changesets before making any repo transaction.
For this reason, Verex requires the repo of your current project.

In your `config.ex` file, add your projects repo to the Verex library.

```elixir
config :verex,
  repo: MyProject.Repo
```

## Migration

Verex will only work on modules with specific fields.
Create a migration to alter the modules' table and add the following fields:

```elixir
alter table(:versioned_module) do
  add :parent_id, :integer
  add :revised_at, :utc_datetime
  add :current_flag, :boolean
end
```

You will also need to add these fields to the modules' schema:
```elixir
schema "versioned_modules" do
  field :parent_id, :integer
  field :revised_at, :utc_datetime
  field :current_flag, :boolean
end
```

## Usage

Verex works by making changes to a changeset prior to any repo transaction. Therefore rather than
calling Ecto.Repo functions such as Repo.insert, Repo.update, or Repo.delete on your versioned module, call
`Verex.Repo.insert`,
`Verex.Repo.update`,
`Verex.Repo.delete`, and
`Verex.Repo.restore`

Please look at the documentation for more information on calling these methods.


Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/verex](https://hexdocs.pm/verex).