omgnetwork / omg-childchain-v2

pronounced /Ch-ch/
Apache License 2.0
5 stars 2 forks source link

Use Postgres to persist timestamp information, not Elixir #105

Closed InoMurko closed 4 years ago

InoMurko commented 4 years ago

time is ewww, fix where it's coming from

Ino  1:25 PM
@mederic @achiurizo I see we’re setting time in Engine.DB.Transaction  and Engine.DB.Output for example  updated_at  and inserted_at

1:26
this “time” is coming from elixir, not postgres as @Ayrat Badykov correctly noticed. this should be fixed so that the time  comes from postgres itself, not us. childchains times can diverge substentially

In order to properly track the life cycle of our transaction, the timestamp in this particular location needs to come from the DB(Postgres) itself and NOT elixir. This requires us to ensure that the field being set at the DB level.

We need to update Engine.DB.Transaction(and other DB tables with timestamps) to:

add :inserted_at, :naive_datetime, default: fragment("now() at time zone 'utc'")
add :updated_at, :naive_datetime, default: fragment("now() at time zone 'utc'")

# instead of using the timestamps helper from elixir
achiurizo commented 4 years ago

To resolve this I think we need to push this timestamp setting down into the migration like so:

# apps/engine/priv/repo/migrations/20200422044422_create_transactions.exs
add :inserted_at, :naive_datetime, default: fragment("now() at time zone 'utc'")
add :updated_at, :naive_datetime, default: fragment("now() at time zone 'utc'")