scoop
Gen_auth: Change from NativeTime to DateTime?
Dear all,
Question
Should I make any changes to the code generated by gen_auth for it to use UTC?
- The
Userschema has a fieldfield :confirmed_at, :naive_datetime– change this to:utc_datetime_usec? - Same module, function
confirm_changesethasnow = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)– change toDateTimeand remove the truncation? - Change the migration for
:userstoadd :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]
Most Liked
aglundahl
If I understand things correctly, :naive_datetime is only the default in Ecto because of compatibility reasons. See this for example: Why use `utc_datetime` over `naive_datetime` for Ecto? - #4 by wojtekmach.
So yes, just go with :utc_datetime_usec!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









