Skip to content

Commit

Permalink
documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jul 25, 2016
1 parent dc6eb6d commit cb56f40
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 41 deletions.
66 changes: 49 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,61 @@
# PaperTrail
# How does it work?

```mix papertrail.install```
PaperTrail saves your every database row change in a seperate table called 'versions'. Library generates a new version record with associated data every time you run PaperTrail.insert/1, PaperTrail.update/1 or PaperTrail.destroy/1 functions. Simply these functions wrap your insert, update or destroy actions in a database transaction, so if your database action fails you won't get a new version.

PaperTrail.create/1, PaperTrail.update/1, PaperTrail.destroy/1

every operation has to go through the changeset function
PaperTrail is inspired by the ruby gem ```paper_trail```. However, unlike the ```paper_trail``` gem this library actually results in less data duplication, faster and more explicit programming model to version your record changes. PaperTrail doesn't need any declaration in your model to work, it simply replaces your Repo.insert, update and destroy functions with PaperTrail ones every time you need versioning. You can you it in your phoenix controller methods for example like this:

PaperTrail.get_version\2, PaperTrail.get_version\1 PaperTrail.get_versions\2, PaperTrail.get_versions\1
```elixir

I will write some tests for this library.
```

**TODO: Add description**
The library code is minimal and tested. It is highly suggested that you check out the source code, there is nothing magical really.

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:

1. Add paper_trail to your list of dependencies in `mix.exs`:

def deps do
[{:paper_trail, "~> 0.0.1"}]
end
def deps do
[{:paper_trail, "~> 0.0.1"}]
end

2. install and compile your dependency:

```mix deps.compile```

3. run this command to generate a migration for versions table in the database:

```mix papertrail.install```

4. run the migration:

```mix ecto.migrate```

Your application is now ready to collect some history!


TODO AREA:

2. Ensure paper_trail is started before your application:
** explain the columns

## Storing version meta data

give originator example


Your versions don't need a model lifecycle callbacks like before_create or before_update for any extra meta data, all your meta data could be stored in one object and that object could be passed as the second optional parameter to PaperTrail.create

## Suggestions

order matter,
don't delete your versions merge them


## Examples

PaperTrail.create/1, PaperTrail.update/1, PaperTrail.destroy/1

every operation has to go through the changeset function

PaperTrail.get_version\2, PaperTrail.get_version\1 PaperTrail.get_versions\2, PaperTrail.get_versions\1

def application do
[applications: [:paper_trail]]
end
PaperTrail.get_current
4 changes: 2 additions & 2 deletions doc/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.12.0">
<title>404 – paper_trail v0.1.1</title>
<title>404 – paper_trail v0.1.3</title>
<link rel="stylesheet" href="dist/app-88251e7c81.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/404.html" />
Expand All @@ -27,7 +27,7 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.1.1
v0.1.3
</h2>
</div>

Expand Down
6 changes: 3 additions & 3 deletions doc/Mix.Tasks.Papertrail.Install.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.12.0">
<title>Mix.Tasks.Papertrail.Install – paper_trail v0.1.1</title>
<title>Mix.Tasks.Papertrail.Install – paper_trail v0.1.3</title>
<link rel="stylesheet" href="dist/app-88251e7c81.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/Mix.Tasks.Papertrail.Install.html" />
Expand All @@ -27,7 +27,7 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.1.1
v0.1.3
</h2>
</div>

Expand Down Expand Up @@ -60,7 +60,7 @@ <h2 class="sidebar-projectVersion">


<h1>
<small class="visible-xs">paper_trail v0.1.1</small>
<small class="visible-xs">paper_trail v0.1.3</small>
Mix.Tasks.Papertrail.Install


Expand Down
6 changes: 3 additions & 3 deletions doc/PaperTrail.Migration.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.12.0">
<title>PaperTrail.Migration – paper_trail v0.1.1</title>
<title>PaperTrail.Migration – paper_trail v0.1.3</title>
<link rel="stylesheet" href="dist/app-88251e7c81.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/PaperTrail.Migration.html" />
Expand All @@ -27,7 +27,7 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.1.1
v0.1.3
</h2>
</div>

Expand Down Expand Up @@ -60,7 +60,7 @@ <h2 class="sidebar-projectVersion">


<h1>
<small class="visible-xs">paper_trail v0.1.1</small>
<small class="visible-xs">paper_trail v0.1.3</small>
PaperTrail.Migration


Expand Down
6 changes: 3 additions & 3 deletions doc/PaperTrail.Version.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.12.0">
<title>PaperTrail.Version – paper_trail v0.1.1</title>
<title>PaperTrail.Version – paper_trail v0.1.3</title>
<link rel="stylesheet" href="dist/app-88251e7c81.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/PaperTrail.Version.html" />
Expand All @@ -27,7 +27,7 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.1.1
v0.1.3
</h2>
</div>

Expand Down Expand Up @@ -60,7 +60,7 @@ <h2 class="sidebar-projectVersion">


<h1>
<small class="visible-xs">paper_trail v0.1.1</small>
<small class="visible-xs">paper_trail v0.1.3</small>
PaperTrail.Version


Expand Down
32 changes: 28 additions & 4 deletions doc/PaperTrail.VersionQueries.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.12.0">
<title>PaperTrail.VersionQueries – paper_trail v0.1.1</title>
<title>PaperTrail.VersionQueries – paper_trail v0.1.3</title>
<link rel="stylesheet" href="dist/app-88251e7c81.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/PaperTrail.VersionQueries.html" />
Expand All @@ -27,7 +27,7 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.1.1
v0.1.3
</h2>
</div>

Expand Down Expand Up @@ -60,7 +60,7 @@ <h2 class="sidebar-projectVersion">


<h1>
<small class="visible-xs">paper_trail v0.1.1</small>
<small class="visible-xs">paper_trail v0.1.3</small>
PaperTrail.VersionQueries


Expand All @@ -84,6 +84,15 @@ <h2>
<a href="#functions">Functions</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#get_current/1">get_current(version)</a>
</div>

<div class="summary-synopsis"><p>Gets the current record of a version</p>
</div>

</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#get_version/1">get_version(record)</a>
</div>
Expand Down Expand Up @@ -140,7 +149,22 @@ <h1 class="section-heading">
</a>
Functions
</h1>
<div class="detail" id="get_version/1">
<div class="detail" id="get_current/1">
<div class="detail-header">
<a href="#get_current/1" class="detail-link" title="Link to this function">
<i class="icon-link"></i>
</a>
<span class="signature">get_current(version)</span>


</div>

<section class="docstring">
<p>Gets the current record of a version</p>

</section>
</div>
<div class="detail" id="get_version/1">
<div class="detail-header">
<a href="#get_version/1" class="detail-link" title="Link to this function">
<i class="icon-link"></i>
Expand Down
30 changes: 27 additions & 3 deletions doc/PaperTrail.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.12.0">
<title>PaperTrail – paper_trail v0.1.1</title>
<title>PaperTrail – paper_trail v0.1.3</title>
<link rel="stylesheet" href="dist/app-88251e7c81.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/PaperTrail.html" />
Expand All @@ -27,7 +27,7 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.1.1
v0.1.3
</h2>
</div>

Expand Down Expand Up @@ -60,7 +60,7 @@ <h2 class="sidebar-projectVersion">


<h1>
<small class="visible-xs">paper_trail v0.1.1</small>
<small class="visible-xs">paper_trail v0.1.3</small>
PaperTrail


Expand Down Expand Up @@ -91,6 +91,15 @@ <h2>
<div class="summary-synopsis"><p>Deletes a record from the database with a related version insertion in one transaction</p>
</div>

</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#get_current/1">get_current(version)</a>
</div>

<div class="summary-synopsis"><p>Gets the current record of a version</p>
</div>

</div>
<div class="summary-row">
<div class="summary-signature">
Expand Down Expand Up @@ -182,6 +191,21 @@ <h1 class="section-heading">

</section>
</div>
<div class="detail" id="get_current/1">
<div class="detail-header">
<a href="#get_current/1" class="detail-link" title="Link to this function">
<i class="icon-link"></i>
</a>
<span class="signature">get_current(version)</span>


</div>

<section class="docstring">
<p>Gets the current record of a version</p>

</section>
</div>
<div class="detail" id="get_version/1">
<div class="detail-header">
<a href="#get_version/1" class="detail-link" title="Link to this function">
Expand Down
6 changes: 3 additions & 3 deletions doc/api-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.12.0">
<title>API Reference – paper_trail v0.1.1</title>
<title>API Reference – paper_trail v0.1.3</title>
<link rel="stylesheet" href="dist/app-88251e7c81.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/api-reference.html" />
Expand All @@ -27,7 +27,7 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.1.1
v0.1.3
</h2>
</div>

Expand Down Expand Up @@ -59,7 +59,7 @@ <h2 class="sidebar-projectVersion">
<div id="content" class="content-inner">

<h1>
<small class="visible-xs">paper_trail v0.1.1</small>
<small class="visible-xs">paper_trail v0.1.3</small>
API Reference
</h1>

Expand Down
2 changes: 1 addition & 1 deletion doc/dist/sidebar_items.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>paper_trail v0.1.1 – Documentation</title>
<title>paper_trail v0.1.3 – Documentation</title>
<meta http-equiv="refresh" content="0; url=api-reference.html">
<meta name="robots" content="noindex">
<meta name="generator" content="ExDoc v0.12.0">
Expand Down
2 changes: 1 addition & 1 deletion test/paper_trail/version_queries_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule PaperTrailTest.VersionQueries do

company = first(Company, :id) |> Repo.one

new_person = Person.changeset(%Person{}, %{
Person.changeset(%Person{}, %{
first_name: "Izel",
last_name: "Nakri",
gender: true,
Expand Down

0 comments on commit cb56f40

Please sign in to comment.