-
Notifications
You must be signed in to change notification settings - Fork 22k
Rails Guides: PostgreSQL timestamp with time zone [ci skip] #53687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Edouard-chin
merged 1 commit into
rails:main
from
andyatkinson:docs/rails-guides-postgresql-timestamp-with-time-zone
Mar 24, 2025
Merged
Rails Guides: PostgreSQL timestamp with time zone [ci skip] #53687
Edouard-chin
merged 1 commit into
rails:main
from
andyatkinson:docs/rails-guides-postgresql-timestamp-with-time-zone
Mar 24, 2025
+28
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ghiculescu
reviewed
Nov 20, 2024
would be great to merge this, eh? |
This guide addition documents how to configure your Rails application to use the data type "timestamp with time zone" (timezone-aware timestamp), instead of the default type, "timestamp without time zone" Support for this data type was added earlier in Active Record, but requires a configuration change in order to use, and from these PR comments, where, why, and how to perform this configuration change wasn't added to the Rails Guides Active Record PostgreSQL documentation from what I could tell Related PR: rails#41084 Guide page: https://guides.rubyonrails.org/active_record_postgresql.html PostgreSQL best practices: https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_timestamp_.28without_time_zone.29
1332c6f
to
f65d592
Compare
Edouard-chin
added a commit
that referenced
this pull request
Mar 24, 2025
…sql-timestamp-with-time-zone Rails Guides: PostgreSQL timestamp with time zone [ci skip]
Edouard-chin
added a commit
that referenced
this pull request
Mar 24, 2025
…sql-timestamp-with-time-zone Rails Guides: PostgreSQL timestamp with time zone [ci skip]
❤️ |
skipkayhil
reviewed
Mar 30, 2025
# config/application.rb | ||
ActiveSupport.on_load(:active_record_postgresqladapter) do | ||
self.datetime_type = :timestamptz | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be inside
config.after_initialize
?
Why is that necessary? This block will run whenever the load hook fires, so the location of this code shouldn't matter.
Edit: original comment was deleted(?) so I've added the quote as context
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This addition to the Active Record PostgreSQL Rails Guide documents how to use a configuration option to change the default timestamp data type from
timestamp without time zone
totimestamp with time zone
(timezone-aware timestamps).Support for this data type was added to Active Record earlier but is not used by default, requiring a configuration change to use. From the PR comments where it was added, there was a suggestion to document how to use this configuration option, prompting this PR.
I created a new Rails 8 application, generating migrations for scaffolds, and realized they weren't using this data type. I made this configuration change, destroyed and regenerated my scaffold migration, and verified the new data type was used.
I welcome your feedback on this guide content, placement within the guide, or anything else.
timestamp with time zone
#41084https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_timestamp_.28without_time_zone.29
Thanks!
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]