Within a Postgres transaction the value of now() does not change, it’s set to the time at the start of the transaction. Would that account for your test scenario?
When you created your schema, you set the default to now. now was evaluated the moment the migration was ran and will always be the same. placed_at will not be not generated every time there’s a new insert like you are expected. You’ll need to either insert it manually in your create/0 function or you can optionally use a Postgres trigger. Updating the function would be the simplest solution.
def create do
%Order{placed_at: DateTime.utc_now()}
end
When I create two order, order_match is created via trigger of database.
I want to test a function that queries order_matchs filtering with datetime, but I can’t because matching_time of order_match are all the same. (matching_time is created by “now()”)
Postgres provides clock_timestamp that is not tied to the beginning of the current transaction. You could also pass the timestamp to the DB from Elixir and obtain it using DateTime.utc_now().