diff --git a/README.md b/README.md index e309fef3..35f3eb38 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,13 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i # {:ok, # %{model: %Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">, # title: "Word on the street is Elixir got its own database versioning library", - # content: "You should try it now!", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 21:42:38>}, + # content: "You should try it now!", id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 21:42:38]}, # version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "insert", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, + # event: "insert", id: 1, inserted_at: ~N[2016-09-15 21:42:38], # item_changes: %{title: "Word on the street is Elixir got its own database versioning library", - # content: "You should try it now!", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 21:42:38>}, + # content: "You should try it now!", id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 21:42:38]}, # item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}}} # => on error(it matches Repo.insert/2): @@ -45,10 +45,10 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i # {:ok, # %{model: %Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">, # title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!", - # id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 22:00:59>}, + # id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 22:00:59]}, # version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "update", id: 2, inserted_at: #Ecto.DateTime<2016-09-15 22:00:59>, + # event: "update", id: 2, inserted_at: ~N[2016-09-15 22:00:59], # item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!"}, # item_id: 1, item_type: "Post", originator_id: nil, originator: nil # meta: nil}}} @@ -61,7 +61,7 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i PaperTrail.get_version(post) # %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "update", id: 2, inserted_at: #Ecto.DateTime<2016-09-15 22:00:59>, + # event: "update", id: 2, inserted_at: ~N[2016-09-15 22:00:59], # item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!"}, # item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}}} @@ -72,13 +72,13 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i # {:ok, # %{model: %Post{__meta__: #Ecto.Schema.Metadata<:deleted, "posts">, # title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!", - # id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 22:00:59>}, + # id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 22:00:59]}, # version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "delete", id: 3, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>, + # event: "delete", id: 3, inserted_at: ~N[2016-09-15 22:22:12], # item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!", - # id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 22:00:59>}, + # id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 22:00:59]}, # item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil}}} Repo.aggregate(Post, :count, :id) # => 0 @@ -87,7 +87,7 @@ PaperTrail is assailed with hundreds of test assertions for each release. Data i PaperTrail.Version.last() # returns the last version in the db by inserted_at # %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "delete", id: 3, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>, + # event: "delete", id: 3, inserted_at: ~N[2016-09-15 22:22:12], # item_changes: %{"title" => "Elixir matures fast", content: "Future is already here, Elixir is the next step!", "id" => 1, # "inserted_at" => "2016-09-15T21:42:38", # "updated_at" => "2016-09-15T22:00:59"}, @@ -105,6 +105,7 @@ The library source code is minimal and well tested. It is suggested to read the ```elixir def deps do [{:paper_trail, "~> 0.8"}] + # if you want to use PaperTrail with Ecto 3.0, use master branch end ``` @@ -278,11 +279,11 @@ When you run PaperTrail.insert/2 transaction, ```first_version_id``` and ```curr company = Company.changeset(%Company{}, %{name: "Acme LLC"}) |> PaperTrail.insert # {:ok, # %{model: %Company{__meta__: #Ecto.Schema.Metadata<:loaded, "companies">, -# name: "Acme LLC", founded_in: nil, id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, -# updated_at: #Ecto.DateTime<2016-09-15 21:42:38>, first_version_id: 1, current_version_id: 1}, +# name: "Acme LLC", founded_in: nil, id: 1, inserted_at: ~N[2016-09-15 21:42:38], +# updated_at: ~N[2016-09-15 21:42:38], first_version_id: 1, current_version_id: 1}, # version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, -# event: "insert", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>, -# item_changes: %{name: "Acme LLC", founded_in: nil, id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>}, +# event: "insert", id: 1, inserted_at: ~N[2016-09-15 22:22:12], +# item_changes: %{name: "Acme LLC", founded_in: nil, id: 1, inserted_at: ~N[2016-09-15 21:42:38]}, # originator_id: nil, origin: "unknown", meta: nil}}} ``` @@ -292,10 +293,10 @@ When you PaperTrail.update/2 a model, ```current_version_id``` gets updated duri edited_company = Company.changeset(company, %{name: "Acme Inc."}) |> PaperTrail.update(origin: "documentation") # {:ok, # %{model: %Company{__meta__: #Ecto.Schema.Metadata<:loaded, "companies">, -# name: "Acme Inc.", founded_in: nil, id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, -# updated_at: #Ecto.DateTime<2016-09-15 23:22:12>, first_version_id: 1, current_version_id: 2}, +# name: "Acme Inc.", founded_in: nil, id: 1, inserted_at: ~N[2016-09-15 21:42:38], +# updated_at: ~N[2016-09-15 23:22:12], first_version_id: 1, current_version_id: 2}, # version: %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, -# event: "update", id: 2, inserted_at: #Ecto.DateTime<2016-09-15 23:22:12>, +# event: "update", id: 2, inserted_at: ~N[2016-09-15 23:22:12], # item_changes: %{name: "Acme Inc."}, originator_id: nil, origin: "documentation", meta: nil}}} ``` @@ -317,18 +318,18 @@ Bang functions assume the operation will always be successful, otherwise functio # => on success: # %Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">, # title: "Word on the street is Elixir got its own database versioning library", - # content: "You should try it now!", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 21:42:38> + # content: "You should try it now!", id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 21:42:38] # } # # => on error raises: Ecto.InvalidChangesetError !! inserted_post_version = PaperTrail.get_version(inserted_post) # %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "insert", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, + # event: "insert", id: 1, inserted_at: ~N[2016-09-15 21:42:38], # item_changes: %{title: "Word on the street is Elixir got its own database versioning library", - # content: "You should try it now!", id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 21:42:38>}, + # content: "You should try it now!", id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 21:42:38]}, # item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil} edit_changeset = Post.changeset(inserted_post, %{ @@ -340,14 +341,14 @@ Bang functions assume the operation will always be successful, otherwise functio # => on success: # %Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">, # title: "Elixir matures fast", content: "Future is already here, you deserve to be awesome!", - # id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 22:00:59>} + # id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 22:00:59]} # # => on error raises: Ecto.InvalidChangesetError !! updated_post_version = PaperTrail.get_version(updated_post) # %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "update", id: 2, inserted_at: #Ecto.DateTime<2016-09-15 22:00:59>, + # event: "update", id: 2, inserted_at: ~N[2016-09-15 22:00:59], # item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!"}, # item_id: 1, item_type: "Post", originator_id: nil, originator: nil # meta: nil} @@ -356,17 +357,17 @@ Bang functions assume the operation will always be successful, otherwise functio # => on success: # %Post{__meta__: #Ecto.Schema.Metadata<:deleted, "posts">, # title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!", - # id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 22:00:59>} + # id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 22:00:59]} # # => on error raises: Ecto.InvalidChangesetError !! PaperTrail.get_version(updated_post) # %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "delete", id: 3, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>, + # event: "delete", id: 3, inserted_at: ~N[2016-09-15 22:22:12], # item_changes: %{title: "Elixir matures fast", content: "Future is already here, Elixir is the next step!", - # id: 1, inserted_at: #Ecto.DateTime<2016-09-15 21:42:38>, - # updated_at: #Ecto.DateTime<2016-09-15 22:00:59>}, + # id: 1, inserted_at: ~N[2016-09-15 21:42:38], + # updated_at: ~N[2016-09-15 22:00:59]}, # item_id: 1, item_type: "Post", originator_id: nil, originator: nil, meta: nil} Repo.aggregate(Post, :count, :id) # => 0 @@ -375,7 +376,7 @@ Bang functions assume the operation will always be successful, otherwise functio PaperTrail.Version.last() # returns the last version in the db by inserted_at # %PaperTrail.Version{__meta__: #Ecto.Schema.Metadata<:loaded, "versions">, - # event: "delete", id: 3, inserted_at: #Ecto.DateTime<2016-09-15 22:22:12>, + # event: "delete", id: 3, inserted_at: ~N[2016-09-15 22:22:12], # item_changes: %{"title" => "Elixir matures fast", content: "Future is already here, Elixir is the next step!", "id" => 1, # "inserted_at" => "2016-09-15T21:42:38", # "updated_at" => "2016-09-15T22:00:59"}, diff --git a/example/.iex.exs b/example/.iex.exs index e69de29b..32247b27 100644 --- a/example/.iex.exs +++ b/example/.iex.exs @@ -0,0 +1 @@ +import Ecto.Query