Skip to content

Commit

Permalink
Merge pull request #51 from rustamtolipov/ecto3
Browse files Browse the repository at this point in the history
Ecto 3.0-rc.1 support
  • Loading branch information
izelnakri committed Oct 31, 2018
2 parents 8044b01 + 4cc2cc0 commit 35da0b2
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 113 deletions.
73 changes: 37 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}}}
Expand All @@ -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}}}

Expand All @@ -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
Expand All @@ -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"},
Expand All @@ -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
```

Expand Down Expand Up @@ -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}}}
```

Expand All @@ -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}}}
```

Expand All @@ -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, %{
Expand All @@ -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}
Expand All @@ -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
Expand All @@ -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"},
Expand Down
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
Loading

0 comments on commit 35da0b2

Please sign in to comment.