scoop

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 User schema has a field field :confirmed_at, :naive_datetime – change this to :utc_datetime_usec?
  • Same module, function confirm_changeset has now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) – change to DateTimeand remove the truncation?
  • Change the migration for :users to add :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

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!

Where Next?

Popular in Questions Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement