-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
121 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters