From 821b897a2d9c2fce11922edbc63019fe9bc74cdc Mon Sep 17 00:00:00 2001 From: Rustam Date: Wed, 24 Oct 2018 17:59:16 +0500 Subject: [PATCH 1/2] Ecto 3.0-rc.1 support --- example/.iex.exs | 1 - example/lib/company.ex | 4 ++-- example/lib/person.ex | 6 +++--- example/lib/repo.ex | 2 +- example/mix.exs | 9 +++++---- example/mix.lock | 15 ++++++++++----- example/test/multi_tenant_company_test.exs | 1 + example/test/multi_tenant_person_test.exs | 7 ++++--- example/test/person_test.exs | 6 +++--- example/test/support/multi_tenant_helper.exs | 10 ++++++++-- lib/paper_trail.ex | 18 +++++++++--------- mix.exs | 7 ++++--- mix.lock | 15 ++++++++++----- .../bang_functions_simple_mode_test.exs | 14 +++++++------- .../bang_functions_strict_mode_test.exs | 14 +++++++------- test/paper_trail/paper_trail_version_test.exs | 10 +++++----- test/paper_trail/uuid_test.exs | 4 ++-- test/paper_trail_strict_mode_test.exs | 6 +++--- test/paper_trail_test.exs | 6 +++--- test/support/multi_tenant_helper.exs | 10 ++++++++-- test/support/repos.ex | 4 ++-- test/support/simple_models.exs | 6 +++--- test/support/strict_models.exs | 6 +++--- 23 files changed, 103 insertions(+), 78 deletions(-) diff --git a/example/.iex.exs b/example/.iex.exs index 32247b27..e69de29b 100644 --- a/example/.iex.exs +++ b/example/.iex.exs @@ -1 +0,0 @@ -import Ecto.Query diff --git a/example/lib/company.ex b/example/lib/company.ex index c0c20b55..360e9408 100644 --- a/example/lib/company.ex +++ b/example/lib/company.ex @@ -15,10 +15,10 @@ defmodule Company do has_many :people, Person - timestamps + timestamps() end - @optional_fields ~w(name is_active website city address facebook twitter founded_in) + @optional_fields ~w(name is_active website city address facebook twitter founded_in)a def changeset(model, params \\ %{}) do model diff --git a/example/lib/person.ex b/example/lib/person.ex index 0b619231..15a8b489 100644 --- a/example/lib/person.ex +++ b/example/lib/person.ex @@ -8,14 +8,14 @@ defmodule Person do field :last_name, :string field :visit_count, :integer field :gender, :boolean - field :birthdate, Ecto.Date + field :birthdate, :date belongs_to :company, Company - timestamps + timestamps() end - @optional_fields ~w(first_name last_name visit_count gender birthdate company_id) + @optional_fields ~w(first_name last_name visit_count gender birthdate company_id)a def changeset(model, params \\ %{}) do model diff --git a/example/lib/repo.ex b/example/lib/repo.ex index 7dca858b..d7293493 100644 --- a/example/lib/repo.ex +++ b/example/lib/repo.ex @@ -1,3 +1,3 @@ defmodule Repo do - use Ecto.Repo, otp_app: :example + use Ecto.Repo, otp_app: :example, adapter: Ecto.Adapters.Postgres end diff --git a/example/mix.exs b/example/mix.exs index 29dfadce..12953eae 100644 --- a/example/mix.exs +++ b/example/mix.exs @@ -31,10 +31,11 @@ defmodule Example.Mixfile do # Type "mix help deps" for more examples and options defp deps do [ - {:postgrex, ">= 0.0.0"}, - {:ecto, ">= 2.0.2"}, - {:poison, ">= 2.1.0"}, - {:paper_trail, ">= 0.7.3"} + {:ecto, "~> 3.0-rc", override: true}, + {:ecto_sql, "~> 3.0-rc", override: true}, + {:postgrex, ">= 0.0.0-rc"}, + {:jason, "~> 1.0"}, + {:paper_trail, path: "../"} ] end end diff --git a/example/mix.lock b/example/mix.lock index fe40fc77..9d35df84 100644 --- a/example/mix.lock +++ b/example/mix.lock @@ -1,8 +1,13 @@ -%{"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []}, - "db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]}, - "decimal": {:hex, :decimal, "1.3.1", "157b3cedb2bfcb5359372a7766dd7a41091ad34578296e951f58a946fcab49c6", [:mix], []}, - "ecto": {:hex, :ecto, "2.1.4", "d1ba932813ec0e0d9db481ef2c17777f1cefb11fc90fa7c142ff354972dfba7e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]}, +%{ + "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []}, + "db_connection": {:hex, :db_connection, "2.0.0-rc.0", "f6960e86b5e524468ec16fb7277e509c784de565ac520213a1813ad2bf7d802f", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, + "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"}, + "ecto": {:hex, :ecto, "3.0.0-rc.1", "c966a270b289739d6895f61bee339065a3075d1df34ddd369d400cf0c936fd6c", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"}, + "ecto_sql": {:hex, :ecto_sql, "3.0.0-rc.0", "a61da743812a47174e8b79dbe6aa7d4a9f7e6dbf8c90cfd7015f3767738b37ba", [:mix], [{:db_connection, "~> 2.0-rc.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.0-rc.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.0-rc.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0-rc.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.2.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, "paper_trail": {:hex, :paper_trail, "0.7.3", "2e65a18c0928264c2e18dccdba7794b847c90a20cfa3a2fd1e2668d7690452d3", [:mix], [{:ecto, ">= 2.1.0", [hex: :ecto, optional: false]}, {:poison, ">= 3.1.0 or >= 2.0.0", [hex: :poison, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: false]}]}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, - "postgrex": {:hex, :postgrex, "0.13.2", "2b88168fc6a5456a27bfb54ccf0ba4025d274841a7a3af5e5deb1b755d95154e", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}} + "postgrex": {:hex, :postgrex, "0.14.0-rc.1", "a88cbeab25c5f3fc505fc6590bd30877a5acf11b448aedb23b41cbc063824ceb", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0-rc.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, + "telemetry": {:hex, :telemetry, "0.2.0", "5b40caa3efe4deb30fb12d7cd8ed4f556f6d6bd15c374c2366772161311ce377", [:mix], [], "hexpm"}, +} diff --git a/example/test/multi_tenant_company_test.exs b/example/test/multi_tenant_company_test.exs index beb9b570..c6ca6308 100644 --- a/example/test/multi_tenant_company_test.exs +++ b/example/test/multi_tenant_company_test.exs @@ -3,6 +3,7 @@ defmodule MultiTenantCompanyTest do import Ecto.Query setup_all do + Repo.delete_all(PaperTrail.Version) MultiTenantHelper.setup_tenant(Repo) :ok end diff --git a/example/test/multi_tenant_person_test.exs b/example/test/multi_tenant_person_test.exs index c6fab082..f62d522b 100644 --- a/example/test/multi_tenant_person_test.exs +++ b/example/test/multi_tenant_person_test.exs @@ -3,6 +3,7 @@ defmodule MultiTenantPersonTest do import Ecto.Query setup_all do + Repo.delete_all(PaperTrail.Version) MultiTenantHelper.setup_tenant(Repo) %Company{} @@ -123,7 +124,7 @@ defmodule MultiTenantPersonTest do company_id: target_company.id, first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), # this is the only problem + birthdate: ~D[1992-04-01], # this is the only problem last_name: "Nakri", gender: true } @@ -135,7 +136,7 @@ defmodule MultiTenantPersonTest do item_changes: %{ first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: target_company.id }, origin: "user:1", @@ -187,7 +188,7 @@ defmodule MultiTenantPersonTest do last_name: "Nakri", gender: true, visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: person.company.id }, origin: nil, diff --git a/example/test/person_test.exs b/example/test/person_test.exs index 181101e7..36b6fa91 100644 --- a/example/test/person_test.exs +++ b/example/test/person_test.exs @@ -105,7 +105,7 @@ defmodule PersonTest do company_id: target_company.id, first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), # this is the only problem + birthdate: ~D[1992-04-01], # this is the only problem last_name: "Nakri", gender: true } @@ -117,7 +117,7 @@ defmodule PersonTest do item_changes: %{ first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: target_company.id }, origin: "user:1", @@ -162,7 +162,7 @@ defmodule PersonTest do last_name: "Nakri", gender: true, visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: person.company.id }, origin: nil, diff --git a/example/test/support/multi_tenant_helper.exs b/example/test/support/multi_tenant_helper.exs index 7261019a..80f5939b 100644 --- a/example/test/support/multi_tenant_helper.exs +++ b/example/test/support/multi_tenant_helper.exs @@ -2,8 +2,6 @@ defmodule MultiTenantHelper do alias Ecto.Adapters.SQL alias Ecto.Changeset - import Mix.Ecto, only: [build_repo_priv: 1] - @migrations_path "migrations" @tenant "tenant_id" @@ -33,4 +31,12 @@ defmodule MultiTenantHelper do def tenant(), do: @tenant defp migrations_path(repo), do: Path.join(build_repo_priv(repo), @migrations_path) + + def source_repo_priv(repo) do + repo.config()[:priv] || "priv/#{repo |> Module.split |> List.last |> Macro.underscore}" + end + + def build_repo_priv(repo) do + Application.app_dir(Keyword.fetch!(repo.config(), :otp_app), source_repo_priv(repo)) + end end diff --git a/lib/paper_trail.ex b/lib/paper_trail.ex index 9ad5df66..1a0a6fb6 100644 --- a/lib/paper_trail.ex +++ b/lib/paper_trail.ex @@ -23,7 +23,7 @@ defmodule PaperTrail do case RepoClient.strict_mode() do true -> Multi.new() - |> Multi.run(:initial_version, fn %{} -> + |> Multi.run(:initial_version, fn repo, %{} -> version_id = get_sequence_id("versions") + 1 changeset_data = @@ -36,7 +36,7 @@ defmodule PaperTrail do initial_version = make_version_struct(%{event: "insert"}, changeset_data, options) repo.insert(initial_version) end) - |> Multi.run(:model, fn %{initial_version: initial_version} -> + |> Multi.run(:model, fn repo, %{initial_version: initial_version} -> updated_changeset = changeset |> change(%{ @@ -46,7 +46,7 @@ defmodule PaperTrail do repo.insert(updated_changeset) end) - |> Multi.run(:version, fn %{initial_version: initial_version, model: model} -> + |> Multi.run(:version, fn repo, %{initial_version: initial_version, model: model} -> target_version = make_version_struct(%{event: "insert"}, model, options) |> serialize() @@ -56,7 +56,7 @@ defmodule PaperTrail do _ -> Multi.new() |> Multi.insert(:model, changeset) - |> Multi.run(:version, fn %{model: model} -> + |> Multi.run(:version, fn repo, %{model: model} -> version = make_version_struct(%{event: "insert"}, model, options) repo.insert(version) end) @@ -140,7 +140,7 @@ defmodule PaperTrail do case client.strict_mode() do true -> Multi.new() - |> Multi.run(:initial_version, fn %{} -> + |> Multi.run(:initial_version, fn repo, %{} -> version_data = changeset.data |> Map.merge(%{ @@ -151,11 +151,11 @@ defmodule PaperTrail do target_version = make_version_struct(%{event: "update"}, target_changeset, options) repo.insert(target_version) end) - |> Multi.run(:model, fn %{initial_version: initial_version} -> + |> Multi.run(:model, fn repo, %{initial_version: initial_version} -> updated_changeset = changeset |> change(%{current_version_id: initial_version.id}) repo.update(updated_changeset) end) - |> Multi.run(:version, fn %{initial_version: initial_version} -> + |> Multi.run(:version, fn repo, %{initial_version: initial_version} -> new_item_changes = initial_version.item_changes |> Map.merge(%{ @@ -168,7 +168,7 @@ defmodule PaperTrail do _ -> Multi.new() |> Multi.update(:model, changeset) - |> Multi.run(:version, fn %{model: _model} -> + |> Multi.run(:version, fn repo, %{model: _model} -> version = make_version_struct(%{event: "update"}, changeset, options) repo.insert(version) end) @@ -245,7 +245,7 @@ defmodule PaperTrail do transaction = Multi.new() |> Multi.delete(:model, struct, options) - |> Multi.run(:version, fn %{} -> + |> Multi.run(:version, fn repo, %{} -> version = make_version_struct(%{event: "delete"}, struct, options) repo.insert(version, options) end) diff --git a/mix.exs b/mix.exs index 42d4baef..09338b8f 100644 --- a/mix.exs +++ b/mix.exs @@ -26,10 +26,11 @@ defmodule PaperTrail.Mixfile do defp deps do [ - {:ecto, ">= 2.1.0"}, - {:poison, ">= 3.1.0 or >= 2.0.0"}, + {:ecto, "~> 3.0-rc", override: true}, + {:ecto_sql, "~> 3.0-rc", override: true}, {:ex_doc, ">= 0.0.0", only: :dev}, - {:postgrex, "~> 0.13.0"} + {:postgrex, ">= 0.0.0-rc"}, + {:jason, "~> 1.0"}, ] end diff --git a/mix.lock b/mix.lock index d1febce7..03110d4c 100644 --- a/mix.lock +++ b/mix.lock @@ -1,9 +1,14 @@ -%{"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []}, - "db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]}, - "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], []}, +%{ + "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []}, + "db_connection": {:hex, :db_connection, "2.0.0-rc.0", "f6960e86b5e524468ec16fb7277e509c784de565ac520213a1813ad2bf7d802f", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, + "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"}, "earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], []}, - "ecto": {:hex, :ecto, "2.1.6", "29b45f393c2ecd99f83e418ea9b0a2af6078ecb30f401481abac8a473c490f84", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]}, + "ecto": {:hex, :ecto, "3.0.0-rc.1", "c966a270b289739d6895f61bee339065a3075d1df34ddd369d400cf0c936fd6c", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"}, + "ecto_sql": {:hex, :ecto_sql, "3.0.0-rc.0", "a61da743812a47174e8b79dbe6aa7d4a9f7e6dbf8c90cfd7015f3767738b37ba", [:mix], [{:db_connection, "~> 2.0-rc.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.0-rc.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.0-rc.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0-rc.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.2.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.16.2", "3b3e210ebcd85a7c76b4e73f85c5640c011d2a0b2f06dcdf5acdb2ae904e5084", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, - "postgrex": {:hex, :postgrex, "0.13.3", "c277cfb2a9c5034d445a722494c13359e361d344ef6f25d604c2353185682bfc", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}} + "postgrex": {:hex, :postgrex, "0.14.0-rc.1", "a88cbeab25c5f3fc505fc6590bd30877a5acf11b448aedb23b41cbc063824ceb", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0-rc.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, + "telemetry": {:hex, :telemetry, "0.2.0", "5b40caa3efe4deb30fb12d7cd8ed4f556f6d6bd15c374c2366772161311ce377", [:mix], [], "hexpm"}, +} diff --git a/test/paper_trail/bang_functions_simple_mode_test.exs b/test/paper_trail/bang_functions_simple_mode_test.exs index 7416f960..ccd3e24b 100644 --- a/test/paper_trail/bang_functions_simple_mode_test.exs +++ b/test/paper_trail/bang_functions_simple_mode_test.exs @@ -359,7 +359,7 @@ defmodule PaperTrailTest.SimpleModeBangFunctions do company_id: inserted_initial_company.id, first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], last_name: "Nakri", gender: true } @@ -372,7 +372,7 @@ defmodule PaperTrailTest.SimpleModeBangFunctions do convert_to_string_map(%{ first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: inserted_initial_company.id }), originator_id: nil, @@ -444,7 +444,7 @@ defmodule PaperTrailTest.SimpleModeBangFunctions do last_name: "Nakri", gender: true, visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: inserted_target_company.id }), originator_id: nil, @@ -826,7 +826,7 @@ defmodule PaperTrailTest.SimpleModeBangFunctions do company_id: inserted_initial_company.id, first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], last_name: "Nakri", gender: true } @@ -839,7 +839,7 @@ defmodule PaperTrailTest.SimpleModeBangFunctions do convert_to_string_map(%{ first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: inserted_initial_company.id }), originator_id: nil, @@ -919,7 +919,7 @@ defmodule PaperTrailTest.SimpleModeBangFunctions do last_name: "Nakri", gender: true, visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: inserted_target_company.id }), originator_id: nil, @@ -1002,6 +1002,6 @@ defmodule PaperTrailTest.SimpleModeBangFunctions do end defp convert_to_string_map(map) do - map |> Poison.encode!() |> Poison.decode!() + map |> Jason.encode!() |> Jason.decode!() end end diff --git a/test/paper_trail/bang_functions_strict_mode_test.exs b/test/paper_trail/bang_functions_strict_mode_test.exs index 3fd792e7..ebbd18fb 100644 --- a/test/paper_trail/bang_functions_strict_mode_test.exs +++ b/test/paper_trail/bang_functions_strict_mode_test.exs @@ -360,7 +360,7 @@ defmodule PaperTrailTest.StrictModeBangFunctions do first_name: "Isaac", visit_count: 10, # this is the only problem - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], last_name: "Nakri", gender: true, first_version_id: inserted_person_version.id, @@ -375,7 +375,7 @@ defmodule PaperTrailTest.StrictModeBangFunctions do convert_to_string_map(%{ first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], current_version_id: updated_person_version.id, company_id: inserted_initial_company.id }), @@ -449,7 +449,7 @@ defmodule PaperTrailTest.StrictModeBangFunctions do last_name: "Nakri", gender: true, visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: inserted_company.id, first_version_id: inserted_person_version.id, current_version_id: updated_person_version.id @@ -840,7 +840,7 @@ defmodule PaperTrailTest.StrictModeBangFunctions do first_name: "Isaac", visit_count: 10, # this is the only problem - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], last_name: "Nakri", gender: true, first_version_id: inserted_person_version.id, @@ -855,7 +855,7 @@ defmodule PaperTrailTest.StrictModeBangFunctions do convert_to_string_map(%{ first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], current_version_id: updated_person_version.id, company_id: inserted_initial_company.id }), @@ -944,7 +944,7 @@ defmodule PaperTrailTest.StrictModeBangFunctions do last_name: "Nakri", gender: true, visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: inserted_company.id, first_version_id: inserted_person_version.id, current_version_id: updated_person_version.id @@ -1029,6 +1029,6 @@ defmodule PaperTrailTest.StrictModeBangFunctions do end defp convert_to_string_map(map) do - map |> Poison.encode!() |> Poison.decode!() + map |> Jason.encode!() |> Jason.decode!() end end diff --git a/test/paper_trail/paper_trail_version_test.exs b/test/paper_trail/paper_trail_version_test.exs index 6a9bf9a5..06859e72 100644 --- a/test/paper_trail/paper_trail_version_test.exs +++ b/test/paper_trail/paper_trail_version_test.exs @@ -10,7 +10,7 @@ defmodule PaperTrailTest.Version do item_id: 1, item_changes: %{first_name: "Izel", last_name: "Nakri"}, origin: "test", - inserted_at: DateTime.from_naive!(~N[1952-04-01 01:00:00.000], "Etc/UTC") + inserted_at: ~N[1952-04-01 01:00:00] } @invalid_attrs %{} @@ -88,7 +88,7 @@ defmodule PaperTrailTest.Version do item_id: 3, item_changes: %{first_name: "Yukihiro", last_name: "Matsumoto"}, origin: "test", - inserted_at: DateTime.from_naive!(~N[1965-04-14 01:00:00.000], "Etc/UTC") + inserted_at: DateTime.from_naive!(~N[1965-04-14 01:00:00], "Etc/UTC") } end @@ -130,7 +130,7 @@ defmodule PaperTrailTest.Version do item_id: 3, item_changes: %{first_name: "Yukihiro", last_name: "Matsumoto"}, origin: "test", - inserted_at: DateTime.from_naive!(~N[1965-04-14 01:00:00.000], "Etc/UTC") + inserted_at: ~N[1965-04-14 01:00:00] } assert Version.last() == nil @@ -147,7 +147,7 @@ defmodule PaperTrailTest.Version do item_id: 2, item_changes: %{first_name: "Brendan", last_name: "Eich"}, origin: "test", - inserted_at: DateTime.from_naive!(~N[1961-07-04 01:00:00.000], "Etc/UTC") + inserted_at: ~N[1961-07-04 01:00:00] }, %{ event: "insert", @@ -155,7 +155,7 @@ defmodule PaperTrailTest.Version do item_id: 3, item_changes: %{first_name: "Yukihiro", last_name: "Matsumoto"}, origin: "test", - inserted_at: DateTime.from_naive!(~N[1965-04-14 01:00:00.000], "Etc/UTC") + inserted_at: ~N[1965-04-14 01:00:00] } ], returning: true, diff --git a/test/paper_trail/uuid_test.exs b/test/paper_trail/uuid_test.exs index e4df6d86..b9629090 100644 --- a/test/paper_trail/uuid_test.exs +++ b/test/paper_trail/uuid_test.exs @@ -66,7 +66,7 @@ defmodule PaperTrailTest.UUIDTest do |> FooItem.changeset(%{title: "hello"}) |> PaperTrail.insert!() - version = Version |> last |> repo.one + version = Version |> last |> repo().one assert version.item_id == "#{item.id}" end end @@ -78,7 +78,7 @@ defmodule PaperTrailTest.UUIDTest do |> BarItem.changeset(%{item_id: "#{:os.system_time}", title: "hello"}) |> PaperTrail.insert!() - version = Version |> last |> repo.one + version = Version |> last |> repo().one assert version.item_id == item.item_id end end diff --git a/test/paper_trail_strict_mode_test.exs b/test/paper_trail_strict_mode_test.exs index bcecfb69..cd605d16 100644 --- a/test/paper_trail_strict_mode_test.exs +++ b/test/paper_trail_strict_mode_test.exs @@ -376,7 +376,7 @@ defmodule PaperTrailStrictModeTest do first_name: "Isaac", visit_count: 10, # this is the only problem - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], last_name: "Nakri", gender: true, first_version_id: insert_person_result[:version].id, @@ -390,7 +390,7 @@ defmodule PaperTrailStrictModeTest do item_changes: %{ first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], current_version_id: version.id, company_id: insert_company_result[:model].id }, @@ -460,7 +460,7 @@ defmodule PaperTrailStrictModeTest do last_name: "Nakri", gender: true, visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: target_company_insertion[:model].id, first_version_id: insert_person_result[:version].id, current_version_id: update_person_result[:version].id diff --git a/test/paper_trail_test.exs b/test/paper_trail_test.exs index 56afeb64..1200ac21 100644 --- a/test/paper_trail_test.exs +++ b/test/paper_trail_test.exs @@ -377,7 +377,7 @@ defmodule PaperTrailTest do company_id: initial_company_insertion[:model].id, first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], last_name: "Nakri", gender: true } @@ -389,7 +389,7 @@ defmodule PaperTrailTest do item_changes: %{ first_name: "Isaac", visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: initial_company_insertion[:model].id }, originator_id: nil, @@ -460,7 +460,7 @@ defmodule PaperTrailTest do last_name: "Nakri", gender: true, visit_count: 10, - birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1), + birthdate: ~D[1992-04-01], company_id: target_company_insertion[:model].id }, originator_id: nil, diff --git a/test/support/multi_tenant_helper.exs b/test/support/multi_tenant_helper.exs index 13e4a32c..5479159c 100644 --- a/test/support/multi_tenant_helper.exs +++ b/test/support/multi_tenant_helper.exs @@ -2,8 +2,6 @@ defmodule PaperTrailTest.MultiTenantHelper do alias Ecto.Adapters.SQL alias Ecto.Changeset - import Mix.Ecto, only: [build_repo_priv: 1] - @migrations_path "migrations" @tenant "tenant_id" @@ -33,4 +31,12 @@ defmodule PaperTrailTest.MultiTenantHelper do def tenant(), do: @tenant defp migrations_path(repo), do: Path.join(build_repo_priv(repo), @migrations_path) + + def source_repo_priv(repo) do + repo.config()[:priv] || "priv/#{repo |> Module.split |> List.last |> Macro.underscore}" + end + + def build_repo_priv(repo) do + Application.app_dir(Keyword.fetch!(repo.config(), :otp_app), source_repo_priv(repo)) + end end diff --git a/test/support/repos.ex b/test/support/repos.ex index ad83afa2..9c4f2180 100644 --- a/test/support/repos.ex +++ b/test/support/repos.ex @@ -1,9 +1,9 @@ defmodule PaperTrail.Repo do - use Ecto.Repo, otp_app: :paper_trail + use Ecto.Repo, otp_app: :paper_trail, adapter: Ecto.Adapters.Postgres end defmodule PaperTrail.UUIDRepo do - use Ecto.Repo, otp_app: :paper_trail + use Ecto.Repo, otp_app: :paper_trail, adapter: Ecto.Adapters.Postgres end defmodule User do diff --git a/test/support/simple_models.exs b/test/support/simple_models.exs index db962564..b047a4ec 100644 --- a/test/support/simple_models.exs +++ b/test/support/simple_models.exs @@ -21,7 +21,7 @@ defmodule SimpleCompany do timestamps() end - @optional_fields ~w(name is_active website city address facebook twitter founded_in) + @optional_fields ~w(name is_active website city address facebook twitter founded_in)a def changeset(model, params \\ %{}) do model @@ -54,14 +54,14 @@ defmodule SimplePerson do field(:last_name, :string) field(:visit_count, :integer) field(:gender, :boolean) - field(:birthdate, Ecto.Date) + field(:birthdate, :date) belongs_to(:company, SimpleCompany, foreign_key: :company_id) timestamps() end - @optional_fields ~w(first_name last_name visit_count gender birthdate company_id) + @optional_fields ~w(first_name last_name visit_count gender birthdate company_id)a def changeset(model, params \\ %{}) do model diff --git a/test/support/strict_models.exs b/test/support/strict_models.exs index 39e1918b..2d70d529 100644 --- a/test/support/strict_models.exs +++ b/test/support/strict_models.exs @@ -24,7 +24,7 @@ defmodule StrictCompany do timestamps() end - @optional_fields ~w(name is_active website city address facebook twitter founded_in) + @optional_fields ~w(name is_active website city address facebook twitter founded_in)a def changeset(model, params \\ %{}) do model @@ -57,7 +57,7 @@ defmodule StrictPerson do field(:last_name, :string) field(:visit_count, :integer) field(:gender, :boolean) - field(:birthdate, Ecto.Date) + field(:birthdate, :date) belongs_to(:first_version, PaperTrail.Version) belongs_to(:current_version, PaperTrail.Version, on_replace: :update) @@ -66,7 +66,7 @@ defmodule StrictPerson do timestamps() end - @optional_fields ~w(first_name last_name visit_count gender birthdate company_id) + @optional_fields ~w(first_name last_name visit_count gender birthdate company_id)a def changeset(model, params \\ %{}) do model From 4cc2cc0dad5c6f216f669b572a5af30f113772f6 Mon Sep 17 00:00:00 2001 From: Rustam Date: Sun, 28 Oct 2018 20:42:08 +0500 Subject: [PATCH 2/2] Updated README.md --- README.md | 73 ++++++++++++++++++++++++------------------------ example/.iex.exs | 1 + 2 files changed, 38 insertions(+), 36 deletions(-) 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