Ecto.DateTime migration

Hi folks, I have a quick question: I have to migrate a very old codebase (Elixir 1.7) to modern version. I have seen that Ecto.DateTime is used and it’s no more available. Do I have to migrate to utc_datetime ?

Thanks

Hi Bruno, yes, you need to. Current Elixir versions have DateTime built in, and custom structure in Ecto is no longer needed.

1 Like

Ok. But if the types overlap, should I still define a migration or it would be ok to just “change” the schema field type ?

Thanks for the answer !

Check your DB and tell us which exact PostgreSQL type is underneath (assuming you use PG?).

The migration defines :datetime for those fields. Yeah, they developed everything in a pretty standard way (for the times)

I meant the actual PG table definition – the one you get by doing \d users; inside psql.

Ok, have to ask, don’t yet have access to it. Just started this task. Thanks for help !

There’s no migration needed for this, it affects how datetimes are represented in Elixir only. The DB column type is still the same.

1 Like

Thanks!

Ok, it’s a actually a timestamp without timezone.

In that case I’d suggest making the field in the Ecto.Schema-derived modules be changed to :utc_datetime just so you are sure any client code (in this case, the Elixir app itself) won’t put a local time inside the DB. But you should test first and check if a migration script is needed because you might end up shifting all your timestamps.

3 Likes

Thanks, I’ll have a look