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

Time columns don't include milliseconds #727

Closed
jwoertink opened this issue Sep 10, 2021 · 1 comment · Fixed by #828
Closed

Time columns don't include milliseconds #727

jwoertink opened this issue Sep 10, 2021 · 1 comment · Fixed by #828
Labels
bug Something isn't working

Comments

@jwoertink
Copy link
Member

jwoertink commented Sep 10, 2021

When we set the created_at and updated_at fields, we just called created_at.value = Time.utc. That value in the DB looks like 2021-09-10 18:08:39+00, but if you actually inspect Time.utc you'll get something that looks like 2021-09-10 18:03:38.655286917 UTC. Storing the milliseconds makes a HUGE difference when you're sorting by created_at in your specs especially if you're doing any window function using created_at.

We need to figure out how to include milliseconds on these fields by default.

Related: #393 if we just let SQL handle it via NOW(), it would be fine.

EDIT: turns out it's all Time columns, not just created_at and updated_at.

@jwoertink
Copy link
Member Author

jwoertink commented Sep 10, 2021

This happens here:

def to_db(value : Time)
value.to_s
end

Time.utc.to_s              #=> "2021-09-10 19:21:22 UTC"
Time.utc.to_s("%F %X.%6N") #=> "2021-09-10 19:21:22.872793"

We account for time formats when pulling the value out of the DB, but not for inserting the value.

@jwoertink jwoertink changed the title Default created_at and updated_at don't include milliseconds Time columns don't include milliseconds Sep 10, 2021
@jwoertink jwoertink added the bug Something isn't working label Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant