Skip to content

Commit

Permalink
Ecto 3.0-rc.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamtolipov committed Oct 24, 2018
1 parent 8044b01 commit 821b897
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 78 deletions.
1 change: 0 additions & 1 deletion example/.iex.exs
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
import Ecto.Query
4 changes: 2 additions & 2 deletions example/lib/company.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions example/lib/person.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/lib/repo.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
defmodule Repo do
use Ecto.Repo, otp_app: :example
use Ecto.Repo, otp_app: :example, adapter: Ecto.Adapters.Postgres
end
9 changes: 5 additions & 4 deletions example/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 10 additions & 5 deletions example/mix.lock
Original file line number Diff line number Diff line change
@@ -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"},
}
1 change: 1 addition & 0 deletions example/test/multi_tenant_company_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule MultiTenantCompanyTest do
import Ecto.Query

setup_all do
Repo.delete_all(PaperTrail.Version)
MultiTenantHelper.setup_tenant(Repo)
:ok
end
Expand Down
7 changes: 4 additions & 3 deletions example/test/multi_tenant_person_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule MultiTenantPersonTest do
import Ecto.Query

setup_all do
Repo.delete_all(PaperTrail.Version)
MultiTenantHelper.setup_tenant(Repo)

%Company{}
Expand Down Expand Up @@ -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
}
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions example/test/person_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions example/test/support/multi_tenant_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
18 changes: 9 additions & 9 deletions lib/paper_trail.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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(%{
Expand All @@ -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()

Expand All @@ -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)
Expand Down Expand Up @@ -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(%{
Expand All @@ -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(%{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -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"},
}
14 changes: 7 additions & 7 deletions test/paper_trail/bang_functions_simple_mode_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Loading

0 comments on commit 821b897

Please sign in to comment.