Add timestamptz as a time zone aware type for PostgreSQL#44601
Add timestamptz as a time zone aware type for PostgreSQL#44601yahonda merged 1 commit intorails:mainfrom
timestamptz as a time zone aware type for PostgreSQL#44601Conversation
bcfd233 to
b91442d
Compare
b1d752a to
3018966
Compare
c253b14 to
2d2136f
Compare
9416503 to
ec322f5
Compare
|
Let me take a look at it. |
|
Before diving into implementation details, Can I get your opinion about adding Background is Based #45348 In PostgreSQL, https://www.postgresql.org/docs/current/rangetypes.html
cc @morgoth |
|
Yep, that sounds reasonable. I'll add it to this PR. |
ec322f5 to
1a22c52
Compare
timestamptz a time zone aware type for Postgrestimestamptz and tstzrange as time zone aware types for PostgreSQL
|
@yahonda updated 👍 |
|
@yahonda Currently Rails is configured to use timezone awareness for "timestamp" column type. It's a bit confusing when the AR logic should be used - should it be for columns without "tz" (to add it to columns that do not support it natively) or with "tz" (that supposed to support it natively)? |
|
Hmm, we use this as an example: So maybe it's intentionally not included by default. I'll remove it from this PR. We can re-add in a separate PR if needed. |
timestamptz and tstzrange as time zone aware types for PostgreSQLtimestamptz as a time zone aware type for PostgreSQL
1a22c52 to
3fee3ac
Compare
3fee3ac to
236eeff
Compare
236eeff to
eb93a8e
Compare
|
@morgoth Thanks for the explanation. Agreed it is difficult to say timezone aware types in Rails just because the database column is timezone aware. Let's keep it as it is. |
eb93a8e to
2c931f0
Compare
|
I rebased again. Keeping the changelog up to date is a full time job 😆 |
|
Looks good to me. Would you address the conflict with CHANGELOG.md? |
rails#41395 added support for the `timestamptz` type on the Postgres adapter. As we found [here](rails#41084 (comment)) this causes issues because in some scenarios the new type is not considered a time zone aware attribute, meaning values of this type in the DB are presented as a `Time`, not an `ActiveSupport::TimeWithZone`. This PR fixes that by ensuring that `timestamptz` is always a time zone aware type, for Postgres users.
2c931f0 to
75c406d
Compare
…ostgres Add `timestamptz` as a time zone aware type for PostgreSQL
|
Thanks for all your help @yahonda ! |
#41395 added support for the
timestamptztype on the Postgres adapter.As we found here this causes issues because in some scenarios the new type is not considered a time zone aware attribute, meaning values of this type in the DB are presented as a
Time, not anActiveSupport::TimeWithZone.This PR fixes that by ensuring that
timestamptzis always a time zone aware type, for Postgres users. A workaround is to do this in an initializer:Or if you don't want this you can opt out in an initializer:
I think this should be backported to
7-0-stable.Fixes #45270