Skip to content

Commit 634df4a

Browse files
committed
Document timezone pitfalls
1 parent d828a6a commit 634df4a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/ecto/migration.ex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ defmodule Ecto.Migration do
302302
updated_at: :changed_at
303303
]
304304
305+
See `timestamps/1` for all supported options.
306+
305307
* `:migration_default_prefix` - Ecto defaults to `nil` for the database prefix for
306308
migrations, but you can configure it via:
307309
@@ -1347,6 +1349,19 @@ defmodule Ecto.Migration do
13471349
* `:null` - determines whether the column accepts null values. Defaults to
13481350
`false`.
13491351
1352+
## Timezones
1353+
1354+
When using `type: :utc_datetime` or `type: :utc_datetime_usec`, Ecto already
1355+
guarantees that all input data must be in UTC format, regardless of your
1356+
database's timezone. For this reason, Ecto defaults to `timestamp`, even in
1357+
PostgreSQL.
1358+
1359+
If you chose to use `type: :timestamptz`, then you must ensure that your
1360+
database is configured to "Etc/UTC", otherwise Ecto and PostgreSQL will be
1361+
out of sync. `mix ecto.create` will create databases in Etc/UTC from
1362+
Ecto v3.14.0, but it is still your responsibility to configure your production
1363+
database accordingly. If you use `:timestamptz` and do not configure the
1364+
timezone, it may lead to incorrect behaviour or Ecto refusing to load data.
13501365
"""
13511366
def timestamps(opts \\ []) when is_list(opts) do
13521367
opts = Keyword.merge(Runner.repo_config(:migration_timestamps, []), opts)

0 commit comments

Comments
 (0)