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

Fixing posgres datetime and timestamp column created with wrong format #4578

Merged
merged 6 commits into from
Jul 20, 2021
Merged

Fixing posgres datetime and timestamp column created with wrong format #4578

merged 6 commits into from
Jul 20, 2021

Conversation

zeotuan
Copy link
Contributor

@zeotuan zeotuan commented Jul 18, 2021

  1. Change default useTz option of datetime and timezone to true in pg column compiler.
  2. Adding additional test to check when empty option object or option object wihout timezone is passed.

@kibertoad
Copy link
Collaborator

kibertoad commented Jul 18, 2021

Doesn't this change default values and hence is a breaking change?

@kibertoad
Copy link
Collaborator

Isn't this still a breaking change, as it will invert values set by users already?

@zeotuan
Copy link
Contributor Author

zeotuan commented Jul 18, 2021

@kibertoad sorry the naming of variables was bad. Yeah i think so. I can change it so that it is not a breaking change anymore. I don't know why but when i was doing it i thought it look cleaner since postgres has tz true as default

@kibertoad
Copy link
Collaborator

It is cleaner, yes, just a bit too late to change it, would require a semver major and still likely to break stuff for people who don't read docs.

tableSql = client
.schemaBuilder()
.table('users', (table) => {
table.datetime('foo', false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing some context since I'm not familiar with the code base, but wouldn't passing false here result in timestamp WITHOUT timezone? Why does it seem inverted?

Copy link
Contributor Author

@zeotuan zeotuan Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing false there would result in timestamptz because :

  • This is the original design which can accept:

    • 2 param: withoutTz=false, precision(this is not documented could be because it would cause confusion)
    • an option object {useTz: boolean, precision: number}(documented)
      image
      you can see that it actually invert what users pass in if not passed as option object
  • And this is the original test for timestamp() which do the same thing as datetime()
    image

The test that you see is just the one i added for datetime. I did changed it to withTz so it does not seem inverted anymore. But as @kibertoad said, it will cause breaking change for people who had already done it the original way so i just added the bug fix and sometest without changing the parameter. Maybe we could request this as feature for future update because i agree that it is not intuiitive.

@zeotuan
Copy link
Contributor Author

zeotuan commented Jul 20, 2021

@kibertoad I changed it so it fixed the bug without making breaking changes. Is there any other change that i need to do?

@kibertoad kibertoad merged commit 55eadcf into knex:master Jul 20, 2021
@kibertoad
Copy link
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants