Skip to content

Commit

Permalink
Merge pull request izelnakri#1 from izelnakri/master
Browse files Browse the repository at this point in the history
merged izelnakri#1 Update Master
  • Loading branch information
abmm committed Sep 25, 2017
2 parents 968a0b0 + 0e978bf commit 09b71bb
Show file tree
Hide file tree
Showing 37 changed files with 2,395 additions and 499 deletions.
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ The library source code is minimal and well tested. It is suggested to read the

```mix papertrail.install```

You might want to edit the types for `:event_id` and `:originator_id` if you're
You might want to edit the types for `:item_id` or `:originator_id` if you're
using UUID or other types for your primary keys before you execute
`mix ecto.migrate`.
Expand All @@ -141,7 +141,7 @@ YES! Make sure you do the steps above.
| Column Name | Type | Description | Entry Method |
| ------------- | ------- | -------------------------- | ------------------------ |
| event | String | either insert, update or delete | Library generates |
| event | String | either "insert", "update" or "delete" | Library generates |
| item_type | String | model name of the reference record | Library generates |
| item_id | configurable (Integer by default) | model id of the reference record | Library generates |
| item_changes | Map | all the changes in this version as a map | Library generates |
Expand Down Expand Up @@ -379,6 +379,59 @@ Bang functions assume the operation will always be successful, otherwise functio
# "updated_at" => "2016-09-15T22:00:59"},
# item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}
```

## Working with multi tenancy

Sometimes you have to deal with applications where you need multi tenancy capabilities,
and you want to keep tracking of the versions of your data on different schemas (PostgreSQL)
or databases (MySQL).

You can use the [Ecto.Query prefix](https://hexdocs.pm/ecto/Ecto.Query.html#module-query-prefix)
in order to switch between different schemas/databases for your own data, so
you can specify in your changeset where to store your record. Example:

```elixir
tenant = "tenant_id"
changeset = User.changeset(%User{}, %{first_name: "Izel", last_name: "Nakri"})

changeset
|> Ecto.Queryable.to_query()
|> Map.put(:prefix, tenant)
|> Repo.insert()
```

PaperTrail also allows you to store the `Version` entries generated by your activity in
different schemas/databases by using the value of the element `:prefix` on the options
of the functions. Example:

```elixir
tenant = "tenant_id"

changeset =
User.changeset(%User{}, %{first_name: "Izel", last_name: "Nakri"})
|> Ecto.Queryable.to_query()
|> Map.put(:prefix, tenant)

PaperTrail.insert(changeset, [prefix: tenant])
```

By doing this, you're storing the new `User` entry into the schema/database
specified by the `:prefix` value (`tenant_id`).

Note that the `User`'s changeset it's sent with the `:prefix`, so PaperTrail **will take care of the
storage of the generated `Version` entry in the desired schema/database**. Make sure
to add this prefix to your changeset before the execution of the PaperTrail function if you want to do versioning on a seperate schema.

PaperTrail can also get versions of records or models from different schemas/databases as well
by using the `:prefix` option. Example:

```elixir
tenant = "tenant_id"
id = 1

PaperTrail.get_versions(User, id, [prefix: tenant])
```

## Suggestions
- PaperTrail.Version(s) order matter,
- don't delete your paper_trail versions, instead you can merge them
Expand All @@ -392,6 +445,8 @@ Many thanks to:
- [Jason Draper](https://github.com/drapergeek) - UUID primary keys feature
- [Josh Taylor](https://github.com/joshuataylor) - Maintenance and new feature suggestions
- [Mitchell Henke](https://github.com/mitchellhenke) - Fixed weird elixir compiler warnings
- [Iván González](https://github.com/dreamingechoes) - Multi tenancy feature and some minor refactors
- [Teo Choong Ping](https://github.com/seymores) - Fixed paper_trail references for newer Elixir versions
- [Izel Nakri](https://github.com/izelnakri) - The Originator of this library. See what I did there ;)

Additional thanks to:
Expand Down
11 changes: 6 additions & 5 deletions doc/.build
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
dist/app-4aef34ad5f.js
dist/app-a07cea761b.css
dist/app-268c9dc719.css
dist/app-4988ddd06b.js
dist/app-4988ddd06b.js.map
fonts/icomoon.eot
fonts/icomoon.svg
fonts/icomoon.ttf
fonts/icomoon.woff
dist/sidebar_items-295d4039c8.js
dist/sidebar_items-5a7da8e21e.js
api-reference.html
index.html
404.html
Mix.Tasks.Papertrail.Install.html
PaperTrail.html
PaperTrail.RepoClient.html
PaperTrail.Version.html
PaperTrail.VersionQueries.html
Mix.Tasks.Papertrail.Install.html
index.html
31 changes: 18 additions & 13 deletions doc/404.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<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.14.5">
<title>404 – paper_trail v0.7.5</title>
<link rel="stylesheet" href="dist/app-a07cea761b.css" />
<meta name="generator" content="ExDoc v0.16.2">
<title>404 – paper_trail v0.7.7</title>
<link rel="stylesheet" href="dist/app-268c9dc719.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/404.html" />

<script src="dist/sidebar_items-295d4039c8.js"></script>
<script src="dist/sidebar_items-5a7da8e21e.js"></script>
</head>
<body data-type="extras">
<script>if(localStorage.getItem('night-mode')) document.body.className += ' night-mode';</script>
<script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>

<div class="main">
<button class="sidebar-toggle">
<i class="icon-menu"></i>
<span class="icon-menu" aria-hidden="true"></span>
<span class="sr-only">Toggle Sidebar</span>
</button>
<section class="sidebar">

Expand All @@ -28,15 +29,15 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.7.5
v0.7.7
</h2>
</div>

</a>

<div class="sidebar-search">
<i class="icon-search"></i>
<input type="text" class="sidebar-searchInput" placeholder="search" autocomplete="off" />
<span class="icon-search" aria-hidden="true"></span>
<input type="text" class="sidebar-searchInput" placeholder="search" aria-label="Search" autocomplete="off" />
</div>

<ul class="sidebar-listNav">
Expand All @@ -49,6 +50,10 @@ <h2 class="sidebar-projectVersion">





<li><a id="tasks-list" href="#full-list">Mix Tasks</a></li>

</ul>
<div class="gradient"></div>
<ul id="full-list" class="sidebar-fullList"></ul>
Expand All @@ -70,20 +75,20 @@ <h2>Page not found</h2>
<p>
<span class="line">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" rel="help" target="_blank">ExDoc</a> (v0.14.5),
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" rel="help" target="_blank">ExDoc</a> (v0.16.2),
</span>
<span class="line">
designed by
<a href="https://twitter.com/dignifiedquire" target="_blank" title="@dignifiedquire">Friedel Ziegelmayer</a>.
</span>
</p>
<button class="night-mode-toggle" />
<button class="night-mode-toggle"><span class="sr-only">Switch theme</span></button>
</footer>
</div>
</div>
</section>
</div>
<script src="dist/app-4aef34ad5f.js"></script>
<script src="dist/app-4988ddd06b.js"></script>
</body>
</html>

51 changes: 27 additions & 24 deletions doc/Mix.Tasks.Papertrail.Install.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<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.14.5">
<title>Mix.Tasks.Papertrail.Install – paper_trail v0.7.5</title>
<link rel="stylesheet" href="dist/app-a07cea761b.css" />
<meta name="generator" content="ExDoc v0.16.2">
<title>papertrail.install – paper_trail v0.7.7</title>
<link rel="stylesheet" href="dist/app-268c9dc719.css" />

<link rel="canonical" href="https://hexdocs.pm/paper_trail/Mix.Tasks.Papertrail.Install.html" />

<script src="dist/sidebar_items-295d4039c8.js"></script>
<script src="dist/sidebar_items-5a7da8e21e.js"></script>
</head>
<body data-type="modules">
<script>if(localStorage.getItem('night-mode')) document.body.className += ' night-mode';</script>
<body data-type="tasks">
<script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>

<div class="main">
<button class="sidebar-toggle">
<i class="icon-menu"></i>
<span class="icon-menu" aria-hidden="true"></span>
<span class="sr-only">Toggle Sidebar</span>
</button>
<section class="sidebar">

Expand All @@ -28,15 +29,15 @@ <h1 class="sidebar-projectName">
paper_trail
</h1>
<h2 class="sidebar-projectVersion">
v0.7.5
v0.7.7
</h2>
</div>

</a>

<div class="sidebar-search">
<i class="icon-search"></i>
<input type="text" class="sidebar-searchInput" placeholder="search" autocomplete="off" />
<span class="icon-search" aria-hidden="true"></span>
<input type="text" class="sidebar-searchInput" placeholder="search" aria-label="Search" autocomplete="off" />
</div>

<ul class="sidebar-listNav">
Expand All @@ -49,6 +50,10 @@ <h2 class="sidebar-projectVersion">





<li><a id="tasks-list" href="#full-list">Mix Tasks</a></li>

</ul>
<div class="gradient"></div>
<ul id="full-list" class="sidebar-fullList"></ul>
Expand All @@ -60,9 +65,8 @@ <h2 class="sidebar-projectVersion">


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

<small class="visible-xs">paper_trail v0.7.7</small>
mix papertrail.install

</h1>

Expand All @@ -72,7 +76,8 @@ <h1>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<i class="icon-link"></i>
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Summary
</h1>
Expand All @@ -99,8 +104,6 @@ <h2>





</section>


Expand All @@ -110,15 +113,17 @@ <h2>
<section id="functions" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#functions">
<i class="icon-link"></i>
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Functions
</h1>
<div class="detail" id="run/1">

<div class="detail-header">
<a href="#run/1" class="detail-link" title="Link to this function">
<i class="icon-link"></i>
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">run(args)</span>

Expand All @@ -137,26 +142,24 @@ <h1 class="section-heading">





<footer class="footer">
<p>
<span class="line">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" rel="help" target="_blank">ExDoc</a> (v0.14.5),
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" rel="help" target="_blank">ExDoc</a> (v0.16.2),
</span>
<span class="line">
designed by
<a href="https://twitter.com/dignifiedquire" target="_blank" title="@dignifiedquire">Friedel Ziegelmayer</a>.
</span>
</p>
<button class="night-mode-toggle" />
<button class="night-mode-toggle"><span class="sr-only">Switch theme</span></button>
</footer>
</div>
</div>
</section>
</div>
<script src="dist/app-4aef34ad5f.js"></script>
<script src="dist/app-4988ddd06b.js"></script>
</body>
</html>

Loading

0 comments on commit 09b71bb

Please sign in to comment.