-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update phx.gen.auth timestamps to match config #5794
Changes from all commits
ef86b8b
bdd4f68
a0bd269
bb4a43e
9b4fcc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ defmodule <%= inspect schema.module %> do | |
field :email, :string | ||
field :password, :string, virtual: true, redact: true | ||
field :hashed_password, :string, redact: true | ||
field :confirmed_at, :naive_datetime | ||
field :confirmed_at, <%= inspect schema.timestamp_type %> | ||
|
||
timestamps(<%= if schema.timestamp_type != :naive_datetime, do: "type: #{inspect schema.timestamp_type}" %>) | ||
end | ||
|
@@ -126,8 +126,11 @@ defmodule <%= inspect schema.module %> do | |
Confirms the account by setting `confirmed_at`. | ||
""" | ||
def confirm_changeset(<%= schema.singular %>) do | ||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) | ||
change(<%= schema.singular %>, confirmed_at: now) | ||
<%= case schema.timestamp_type do %> | ||
<% :naive_datetime -> %>now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) | ||
<% :utc_datetime -> %>now = DateTime.utc_now() |> DateTime.truncate(:second) | ||
<% :utc_datetime_usec -> %>now = DateTime.utc_now() |> DateTime.truncate(:microsecond) | ||
<% end %>change(<%= schema.singular %>, confirmed_at: now) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only handling the 3 documented values; formatted so as to not produce extraneous empty lines when rendered. I noticed Elixir 1.15 supports the shorter |
||
end | ||
|
||
@doc """ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would output one of
:naive_datetime
,:utc_datetime
or:utc_datetime_usec
.I understand from the first note in https://hexdocs.pm/ecto/Ecto.Schema.html#module-primitive-types that those are valid values both in the schema definition and in the migration file.