Skip to content
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

Use timestamps with timezone when set as the default for postgresql. #668

Closed
thomasdziedzic opened this issue Jul 18, 2022 · 5 comments
Closed

Comments

@thomasdziedzic
Copy link

I have the following in config/initializers/active_record.rb:

require "active_record/connection_adapters/postgresql_adapter"
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamptz

As documented in https://guides.rubyonrails.org/configuring.html#activerecord-connectionadapters-postgresqladapter-datetime-type which sets the default to use timestamp with time zone.

When I installed good_job with bin/rails g good_job:install and ran bin/rails db:migrate it used timestamps without a timezone for the good_job fields and a datetime for the created_at and updated_at columns:

    t.timestamp "scheduled_at"
    t.timestamp "performed_at"
    t.timestamp "finished_at"
...
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
...
    t.timestamp "cron_at"

I am trying to use timestamps with timezones throughout my application, so I was wondering:

  1. Would it be possible for good_job to use the value for ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type to generate the good_job migration?
  2. Could I change the timestamps to a datetime in the migration without issue?
@bensheldon
Copy link
Owner

Yep, I don't foresee any problems with your configuration. I would expect GoodJob's migration to pick up the base configuration. GoodJob is not doing anything special with ActiveRecord.

@bensheldon
Copy link
Owner

Oh, also thank you for flagging the inconsistency of timestamp vs datetime. They should be functionally equivalent and is just an inconsistent oversight on my part.

@bensheldon
Copy link
Owner

@thomasdziedzic I wanted to follow-up. Are you successful in creating GoodJob timestamps with timezones?

@dillonhafer
Copy link

I use the same postgres initializer and it appears to use timestamptz for me
Screenshot 2022-12-18 at 13 31 49

@thomasdziedzic
Copy link
Author

@bensheldon I can confirm that I've been successfully using timestamps with timezones on the good_job tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants