luckyframework / luckyframework/avram

Adding ensure UTC default to DB with config option

Open
#732 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request hacktoberfest
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

When you create a new DB, postgres seems to set the timezone to the host machine by default. This could lead to some odd behavior, especially in development, where your local DB is in PST, but your production DB is in UTC.

Postgres allows you to set this timezone at the session, DB, and global levels. What we could do is add some SQL to set this when you first create your DB:

```crystal
execute <<-SQL
alter database #{Avram::Migrator::Runner.db_name} set time zone '#{Avram.settings.default_timezone}';
SQL
```

By default we could have a habitat setting `default_timezone` that's `UTC`. Then if you wanted to change this, you could. If you inherit a DB, then this would never affect you since you'd never run the create task.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by locating the database creation task, Avram settings, and the migrator runner; then trace where the database name and default timezone are available. Done means new databases default to UTC, with a configuration option for another timezone, and the behavior is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.