There are four time zones to consider:
- Ruby process
- config.active_record.default_timezone -What time zone to interpret the time received from the DB
NOW()etc. of SQL statement
Development environment (Docker)
Support by adding
ENV TZ Asia/Tokyo to
Support by setting
TZ = Asia/Tokyo in the environment variable
config.active_record.default_timezone = :local
Execute the following query by connecting to each DB of development environment and production environment
ALTER DATABASE db_name SET timezone TO'Asia/Tokyo';
Since it is the writing method for Postgres, the writing method may be different depending on the type of DB.
It is reflected when reconnecting to DB.
When you execute
rails:db:migrate, the time zone will be restored, but it’s good because you rarely write SQL statements in Rails in the first place.
There seems to be a way to set an environment variable in docker-compose.yml, but it didn’t work.