Skip to content

Commit 8f387ed

Browse files
committed
Upgrades ecto to ~> 3.0
* Ecto.Changeset.cast/3 deprecated usage of binary keys, so a refactoring was applied to solve this. ` warning: non-atom keys in cast/3 is deprecated. All keys must be atoms, got: `"reset_password_token"` ` * Removed timex_ecto lib since ecto 3.0 does not support it * Passing :adapter via config is deprecated in favor of passing it on use Ecto.Repo * Ecto.migrations_path/1 was moved to Ecto.Migrator module * postgrex lib ~> 0.14.0
1 parent bd81623 commit 8f387ed

File tree

11 files changed

+33
-30
lines changed

11 files changed

+33
-30
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,19 @@ defmodule MyProject.Accounts.User do
176176
timestamps()
177177
end
178178

179+
@fields coherence_fields() ++ ~w(name email) |> Enum.map(&String.to_atom/1)
180+
179181
def changeset(model, params \\ %{}) do
180182
model
181-
|> cast(params, [:name, :email] ++ coherence_fields) # Add this
183+
|> cast(params, @fields) # Add this
182184
|> validate_required([:name, :email])
183185
|> validate_format(:email, ~r/@/)
184186
|> validate_coherence(params) # Add this
185187
end
186188

187189
def changeset(model, params, :password) do
188190
model
189-
|> cast(params, ~w(password password_confirmation reset_password_token reset_password_sent_at))
191+
|> cast(params, ~w(password password_confirmation reset_password_token reset_password_sent_at)a)
190192
|> validate_coherence_password_reset(params)
191193
end
192194
end

lib/mix/tasks/coh.clean.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ defmodule Mix.Tasks.Coh.Clean do
4747

4848
import Coherence.Mix.Utils
4949
import Mix.Ecto
50+
import Ecto.Migrator, only: [migrations_path: 1]
5051

5152
alias Mix.Tasks.Coh.Install
5253

lib/mix/tasks/coh.install.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ defmodule Mix.Tasks.Coh.Install do
119119
import Macro, only: [camelize: 1, underscore: 1]
120120
import Mix.Generator
121121
import Mix.Ecto
122+
import Ecto.Migrator, only: [migrations_path: 1]
122123
import Coherence.Mix.Utils
123124

124125
@shortdoc "Configure the Coherence Package"

mix.exs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ defmodule Coherence.Mixfile do
3030
applications: [
3131
:logger,
3232
:comeonin,
33-
:ecto,
33+
:ecto_sql,
3434
:elixir_uuid,
3535
:phoenix_swoosh,
36-
:timex_ecto,
3736
:tzdata,
3837
:plug,
3938
:phoenix,
@@ -47,7 +46,7 @@ defmodule Coherence.Mixfile do
4746

4847
defp deps do
4948
[
50-
{:ecto, "~> 2.0"},
49+
{:ecto_sql, "~> 3.0"},
5150
{:comeonin, "~> 4.0"},
5251
{:bcrypt_elixir, "~> 1.1"},
5352
{:phoenix, "~> 1.3"},
@@ -56,11 +55,10 @@ defmodule Coherence.Mixfile do
5655
{:elixir_uuid, "~> 1.2"},
5756
{:phoenix_swoosh, "~> 0.2"},
5857
{:timex, "~> 3.3"},
59-
{:timex_ecto, "~> 3.3"},
6058
{:floki, "~> 0.19", only: :test},
6159
{:ex_doc, "~> 0.18.0", only: :dev},
6260
{:earmark, "~> 1.2", only: :dev, override: true},
63-
{:postgrex, ">= 0.0.0", only: :test},
61+
{:postgrex, "~> 0.14.0", only: :test},
6462
{:dialyxir, "~> 0.5", only: [:dev], runtime: false},
6563
{:credo, "~> 0.8", only: [:dev, :test]},
6664
{:plug, "~> 1.6"}

mix.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"comeonin": {:hex, :comeonin, "4.1.1", "c7304fc29b45b897b34142a91122bc72757bc0c295e9e824999d5179ffc08416", [:mix], [{:argon2_elixir, "~> 1.2", [hex: :argon2_elixir, repo: "hexpm", optional: true]}, {:bcrypt_elixir, "~> 0.12.1 or ~> 1.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: true]}, {:pbkdf2_elixir, "~> 0.12", [hex: :pbkdf2_elixir, repo: "hexpm", optional: true]}], "hexpm"},
77
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
88
"credo": {:hex, :credo, "0.10.0", "66234a95effaf9067edb19fc5d0cd5c6b461ad841baac42467afed96c78e5e9e", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
9-
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
9+
"db_connection": {:hex, :db_connection, "2.0.2", "440c05518b0bdca0469dafaf45403597430448c1281def14ef9ccaa41833ea1e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
1010
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
1111
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
1212
"earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
13-
"ecto": {:hex, :ecto, "2.2.10", "e7366dc82f48f8dd78fcbf3ab50985ceeb11cb3dc93435147c6e13f2cda0992e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
13+
"earmark": {:hex, :earmark, "1.3.0", "17f0c38eaafb4800f746b457313af4b2442a8c2405b49c645768680f900be603", [:mix], [], "hexpm"},
14+
"ecto": {:hex, :ecto, "3.0.3", "018a3df0956636f84eb3033d807485a7d3dea8474f47b90da5cb8073444c4384", [: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"},
15+
"ecto_sql": {:hex, :ecto_sql, "3.0.2", "0e04cbc183b91ea0085c502226befcd237a4ac31c204fd4be8d4db6676b5f10d", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.2.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
1416
"elixir_make": {:hex, :elixir_make, "0.4.2", "332c649d08c18bc1ecc73b1befc68c647136de4f340b548844efc796405743bf", [:mix], [], "hexpm"},
1517
"elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"},
1618
"ex_doc": {:hex, :ex_doc, "0.18.4", "4406b8891cecf1352f49975c6d554e62e4341ceb41b9338949077b0d4a97b949", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
@@ -34,12 +36,10 @@
3436
"phoenix_swoosh": {:hex, :phoenix_swoosh, "0.2.0", "a7e0b32077cd6d2323ae15198839b05d9caddfa20663fd85787479e81f89520e", [:mix], [{:phoenix, "~> 1.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.2", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:swoosh, "~> 0.1", [hex: :swoosh, repo: "hexpm", optional: false]}], "hexpm"},
3537
"plug": {:hex, :plug, "1.6.2", "e06a7bd2bb6de5145da0dd950070110dce88045351224bd98e84edfdaaf5ffee", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
3638
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
37-
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
38-
"postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
3939
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
4040
"swoosh": {:hex, :swoosh, "0.16.1", "bbe8e7fd90099ac9ad4c7ae751a003e1ecd5726962b26f13af7f95e741f81b5c", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.12", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"},
41-
"timex": {:hex, :timex, "3.3.0", "e0695aa0ddb37d460d93a2db34d332c2c95a40c27edf22fbfea22eb8910a9c8d", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
42-
"timex_ecto": {:hex, :timex_ecto, "3.3.0", "d5bdef09928e7a60f10a0baa47ce653f29b43d6fee87b30b236b216d0e36b98d", [:mix], [{:ecto, "~> 2.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:timex, "~> 3.1", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm"},
4341
"tzdata": {:hex, :tzdata, "0.5.17", "50793e3d85af49736701da1a040c415c97dc1caf6464112fd9bd18f425d3053b", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
4442
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
43+
"postgrex": {:hex, :postgrex, "0.14.0", "f3d6ffea1ca8a156e0633900a5338a3d17b00435227726baed8982718232b694", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.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"},
44+
"timex": {:hex, :timex, "3.4.2", "d74649c93ad0e12ce5b17cf5e11fbd1fb1b24a3d114643e86dba194b64439547", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
4545
}

priv/templates/coh.install/models/coherence/invitation.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule <%= base %>.Coherence.Invitation do
2525
@spec changeset(Ecto.Schema.t(), Map.t()) :: Ecto.Changeset.t()
2626
def changeset(model, params \\ %{}) do
2727
model
28-
|> cast(params, ~w(name email token))
28+
|> cast(params, ~w(name email token)a)
2929
|> validate_required([:name, :email])
3030
|> unique_constraint(:email)
3131
|> validate_format(:email, ~r/@/)

priv/templates/coh.install/models/coherence/rememberable.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule <%= base %>.Coherence.Rememberable do
3030
@spec changeset(Ecto.Schema.t(), Map.t()) :: Ecto.Changeset.t()
3131
def changeset(model, params \\ %{}) do
3232
model
33-
|> cast(params, ~w(series_hash token_hash token_created_at user_id))
33+
|> cast(params, ~w(series_hash token_hash token_created_at user_id)a)
3434
|> validate_required(~w(series_hash token_hash token_created_at user_id)a)
3535
end
3636

priv/templates/coh.install/models/coherence/user.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ defmodule <%= user_schema %> do
1414
timestamps()
1515
end
1616

17+
@fields coherence_fields() ++ ~w(name email)a |> Enum.map(&String.to_atom/1)
1718
@doc false
1819
@spec changeset(Ecto.Schema.t(), Map.t()) :: Ecto.Changeset.t()
1920
def changeset(model, params \\ %{}) do
2021
model
21-
|> cast(params, [:name, :email] ++ coherence_fields())
22+
|> cast(params, @fields)
2223
|> validate_required([:name, :email])
2324
|> validate_format(:email, ~r/@/)
2425
|> unique_constraint(:email)
@@ -31,7 +32,7 @@ defmodule <%= user_schema %> do
3132
model
3233
|> cast(
3334
params,
34-
~w(password password_confirmation reset_password_token reset_password_sent_at)
35+
~w(password password_confirmation reset_password_token reset_password_sent_at)a
3536
)
3637
|> validate_coherence_password_reset(params)
3738
end

test/schema_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ defmodule CoherenceTest.Schema do
100100
assert cs.errors == [
101101
password:
102102
{"should be at least %{count} character(s)",
103-
[count: 4, validation: :length, min: 4]}
103+
[count: 4, validation: :length, kind: :min]}
104104
]
105105
end
106106

test/support/repo.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
defmodule TestCoherence.Repo do
2-
use Ecto.Repo, otp_app: :coherence
2+
use Ecto.Repo, otp_app: :coherence, adapter: Ecto.Adapters.Postgres
33
end

0 commit comments

Comments
 (0)