Dear all,
Question
Should I make any changes to the code generated by gen_auth
for it to use UTC?
- The
User
schema has a fieldfield :confirmed_at, :naive_datetime
– change this to:utc_datetime_usec
? - Same module, function
confirm_changeset
hasnow = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
– change toDateTime
and remove the truncation? - Change the migration for
:users
toadd :confirmed_at, :utc_datetime
?
I’m asking because I feel I’m missing something obvious and I haven’t found this covered somewhere. Feels like I’ve been wasting a whole lot of time on this.
The Setup
I’m starting a brand new project and I want to set it up as neatly as possible from the very beginning.
I have MyApp.Schema
module that sets up binary IDs and options for timestamps as :utc_datetime_usec
.
defmodule MyApp.Schema do
defmacro __using__(_) do
quote do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
@timestamps_opts [type: :utc_datetime_usec]
end
end
end
Also, in config.exs
I have set the option for migration_timestamps
like this.
config :my_app,
ecto_repos: [MyApp.Repo],
generators: [binary_id: true],
migration_timestamps: [type: :utc_datetime_usec]