Skip to content

Commit

Permalink
Upgrades ecto to ~> 3.0
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
norbajunior committed Nov 22, 2018
1 parent bd81623 commit 8f387ed
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 30 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,19 @@ defmodule MyProject.Accounts.User do
timestamps()
end

@fields coherence_fields() ++ ~w(name email) |> Enum.map(&String.to_atom/1)

def changeset(model, params \\ %{}) do
model
|> cast(params, [:name, :email] ++ coherence_fields) # Add this
|> cast(params, @fields) # Add this
|> validate_required([:name, :email])
|> validate_format(:email, ~r/@/)
|> validate_coherence(params) # Add this
end

def changeset(model, params, :password) do
model
|> cast(params, ~w(password password_confirmation reset_password_token reset_password_sent_at))
|> cast(params, ~w(password password_confirmation reset_password_token reset_password_sent_at)a)
|> validate_coherence_password_reset(params)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/mix/tasks/coh.clean.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ defmodule Mix.Tasks.Coh.Clean do

import Coherence.Mix.Utils
import Mix.Ecto
import Ecto.Migrator, only: [migrations_path: 1]

alias Mix.Tasks.Coh.Install

Expand Down
1 change: 1 addition & 0 deletions lib/mix/tasks/coh.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ defmodule Mix.Tasks.Coh.Install do
import Macro, only: [camelize: 1, underscore: 1]
import Mix.Generator
import Mix.Ecto
import Ecto.Migrator, only: [migrations_path: 1]
import Coherence.Mix.Utils

@shortdoc "Configure the Coherence Package"
Expand Down
8 changes: 3 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ defmodule Coherence.Mixfile do
applications: [
:logger,
:comeonin,
:ecto,
:ecto_sql,
:elixir_uuid,
:phoenix_swoosh,
:timex_ecto,
:tzdata,
:plug,
:phoenix,
Expand All @@ -47,7 +46,7 @@ defmodule Coherence.Mixfile do

defp deps do
[
{:ecto, "~> 2.0"},
{:ecto_sql, "~> 3.0"},
{:comeonin, "~> 4.0"},
{:bcrypt_elixir, "~> 1.1"},
{:phoenix, "~> 1.3"},
Expand All @@ -56,11 +55,10 @@ defmodule Coherence.Mixfile do
{:elixir_uuid, "~> 1.2"},
{:phoenix_swoosh, "~> 0.2"},
{:timex, "~> 3.3"},
{:timex_ecto, "~> 3.3"},
{:floki, "~> 0.19", only: :test},
{:ex_doc, "~> 0.18.0", only: :dev},
{:earmark, "~> 1.2", only: :dev, override: true},
{:postgrex, ">= 0.0.0", only: :test},
{:postgrex, "~> 0.14.0", only: :test},
{:dialyxir, "~> 0.5", only: [:dev], runtime: false},
{:credo, "~> 0.8", only: [:dev, :test]},
{:plug, "~> 1.6"}
Expand Down
12 changes: 6 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"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"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
"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"},
"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"},
"db_connection": {:hex, :db_connection, "2.0.2", "440c05518b0bdca0469dafaf45403597430448c1281def14ef9ccaa41833ea1e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
"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"},
"earmark": {:hex, :earmark, "1.3.0", "17f0c38eaafb4800f746b457313af4b2442a8c2405b49c645768680f900be603", [:mix], [], "hexpm"},
"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"},
"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"},
"elixir_make": {:hex, :elixir_make, "0.4.2", "332c649d08c18bc1ecc73b1befc68c647136de4f340b548844efc796405743bf", [:mix], [], "hexpm"},
"elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.4", "4406b8891cecf1352f49975c6d554e62e4341ceb41b9338949077b0d4a97b949", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
Expand All @@ -34,12 +36,10 @@
"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"},
"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"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
"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"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"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"},
"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"},
"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"},
"tzdata": {:hex, :tzdata, "0.5.17", "50793e3d85af49736701da1a040c415c97dc1caf6464112fd9bd18f425d3053b", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
"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"},
"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"},
}
2 changes: 1 addition & 1 deletion priv/templates/coh.install/models/coherence/invitation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule <%= base %>.Coherence.Invitation do
@spec changeset(Ecto.Schema.t(), Map.t()) :: Ecto.Changeset.t()
def changeset(model, params \\ %{}) do
model
|> cast(params, ~w(name email token))
|> cast(params, ~w(name email token)a)
|> validate_required([:name, :email])
|> unique_constraint(:email)
|> validate_format(:email, ~r/@/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule <%= base %>.Coherence.Rememberable do
@spec changeset(Ecto.Schema.t(), Map.t()) :: Ecto.Changeset.t()
def changeset(model, params \\ %{}) do
model
|> cast(params, ~w(series_hash token_hash token_created_at user_id))
|> cast(params, ~w(series_hash token_hash token_created_at user_id)a)
|> validate_required(~w(series_hash token_hash token_created_at user_id)a)
end

Expand Down
5 changes: 3 additions & 2 deletions priv/templates/coh.install/models/coherence/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ defmodule <%= user_schema %> do
timestamps()
end

@fields coherence_fields() ++ ~w(name email)a |> Enum.map(&String.to_atom/1)
@doc false
@spec changeset(Ecto.Schema.t(), Map.t()) :: Ecto.Changeset.t()
def changeset(model, params \\ %{}) do
model
|> cast(params, [:name, :email] ++ coherence_fields())
|> cast(params, @fields)
|> validate_required([:name, :email])
|> validate_format(:email, ~r/@/)
|> unique_constraint(:email)
Expand All @@ -31,7 +32,7 @@ defmodule <%= user_schema %> do
model
|> cast(
params,
~w(password password_confirmation reset_password_token reset_password_sent_at)
~w(password password_confirmation reset_password_token reset_password_sent_at)a
)
|> validate_coherence_password_reset(params)
end
Expand Down
2 changes: 1 addition & 1 deletion test/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ defmodule CoherenceTest.Schema do
assert cs.errors == [
password:
{"should be at least %{count} character(s)",
[count: 4, validation: :length, min: 4]}
[count: 4, validation: :length, kind: :min]}
]
end

Expand Down
2 changes: 1 addition & 1 deletion test/support/repo.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
defmodule TestCoherence.Repo do
use Ecto.Repo, otp_app: :coherence
use Ecto.Repo, otp_app: :coherence, adapter: Ecto.Adapters.Postgres
end
22 changes: 11 additions & 11 deletions test/support/schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule TestCoherence.User do
end

@required_fields ~w(email name)a
@optional_fields ~w() ++ coherence_fields()
@optional_fields ~w() ++ coherence_fields() |> Enum.map(&String.to_atom/1)

def changeset(model, params \\ %{}) do
model
Expand All @@ -28,7 +28,7 @@ defmodule TestCoherence.User do
model
|> cast(
params,
~w(password password_confirmation reset_password_token reset_password_sent_at)
~w(password password_confirmation reset_password_token reset_password_sent_at)a
)
|> validate_coherence_password_reset(params)
end
Expand Down Expand Up @@ -63,7 +63,7 @@ defmodule TestCoherence.Invitation do

def changeset(model, params \\ %{}) do
model
|> cast(params, ~w(name email token))
|> cast(params, ~w(name email token)a)
|> validate_required([:name, :email])
|> unique_constraint(:email)
|> validate_format(:email, ~r/@/)
Expand All @@ -84,7 +84,7 @@ defmodule TestCoherence.Account do
end

@required_fields ~w(email name)a
@optional_fields ~w() ++ coherence_fields()
@optional_fields ~w() ++ coherence_fields() |> Enum.map(&String.to_atom/1)

def changeset(model, params \\ %{}) do
model
Expand All @@ -98,7 +98,7 @@ defmodule TestCoherence.Account do
model
|> cast(
params,
~w(password password_confirmation reset_password_token reset_password_sent_at)
~w(password password_confirmation reset_password_token reset_password_sent_at)a
)
|> validate_coherence_password_reset(params)
end
Expand All @@ -119,7 +119,7 @@ defmodule TestCoherence.Coherence.User do
end

@required_fields ~w(email name)a
@optional_fields ~w() ++ coherence_fields()
@optional_fields ~w() ++ coherence_fields() |> Enum.map(&String.to_atom/1)

def changeset(model, params \\ %{}) do
model
Expand All @@ -134,7 +134,7 @@ defmodule TestCoherence.Coherence.User do
model
|> cast(
params,
~w(password password_confirmation reset_password_token reset_password_sent_at)
~w(password password_confirmation reset_password_token reset_password_sent_at)a
)
|> validate_coherence_password_reset(params)
end
Expand All @@ -155,7 +155,7 @@ defmodule TestCoherence.Coherence.Invitation do

def changeset(model, params \\ %{}) do
model
|> cast(params, ~w(name email token))
|> cast(params, ~w(name email token)a)
|> validate_required([:name, :email])
|> unique_constraint(:email)
|> validate_format(:email, ~r/@/)
Expand All @@ -180,7 +180,7 @@ defmodule TestCoherence.Coherence.Account do
end

@required_fields ~w(email name)a
@optional_fields ~w() ++ coherence_fields()
@optional_fields ~w() ++ coherence_fields() |> Enum.map(&String.to_atom/1)

def changeset(model, params \\ %{}) do
model
Expand All @@ -194,7 +194,7 @@ defmodule TestCoherence.Coherence.Account do
model
|> cast(
params,
~w(password password_confirmation reset_password_token reset_password_sent_at)
~w(password password_confirmation reset_password_token reset_password_sent_at)a
)
|> validate_coherence_password_reset(params)
end
Expand All @@ -220,7 +220,7 @@ defmodule TestCoherence.Coherence.Rememberable do

def changeset(model, params \\ %{}) do
model
|> cast(params, ~w(series_hash token_hash token_created_at user_id))
|> cast(params, ~w(series_hash token_hash token_created_at user_id)a)
|> validate_required(~w(series_hash token_hash token_created_at user_id)a)
end

Expand Down

0 comments on commit 8f387ed

Please sign in to comment.