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
feat: option to allow specifying the default precision for auto-generated timestamp columns #16330
feat: option to allow specifying the default precision for auto-generated timestamp columns #16330
Conversation
Your PR description talks about postgres but the tests you are updating are for mariadb/mysql. Is that correct? |
Yeah, as far as I can tell, #14505 changed the precision for all dialects, so I think it makes sense to undo this part of the change everywhere too. It seems like the mariadb/mysql tests are just a bit more detailed. (I'm having trouble running the complete test suite locally, so I'm iterating a bit using your CI setup 😇 ) |
No worries, I do that quite often as well. Running integration tests on all dialects locally is not always worth the additional effort |
Ah, the failing mariadb/mysql indicate that with my change, The MySQL docs say:
I guess that clears up why #14505 included this change in the first place 😅 Then my new point of view is that sequelize should only set an explicit precision for the mariadb/mysql dialects, as they're the ones diverging from the SQL standard 🤔 I don't know exactly how to accomplish that without breaking something else, so I think I'll need help with that! My alternative is to apply a migration that changes the type of 216 columns in my DB schema from |
@ephys, I'd like to hear your input on this when you have some time 🤗 |
The thing is, we should likely set it to 3 by default instead of 6 or letting it default to 6, because the Date object's own precision only goes up to 3 :( We'll need to wait for Temporal to have something capable of representing a precision of 6 decimal places |
Hey @ephys, thanks for your reply!
That makes sense, but maybe there could then be a way to override the default precision for long-time loyal users? ;) If not, I can also live with that and just write that migration to change the types of those 216 columns from (We've been using Postgres+Sequelize since version 2.1.3, and I can tell that ironically the auto-provisioned timestamp columns used to come out as |
…sion of createdAt/updatedAt/deletedAt
c0cc8e6
to
c67a346
Compare
I took the liberty of changing the PR to introduce a |
@ephys, sorry to ping you, but would you mind giving some kind of signal? I have an opportunity to change those 216 columns to |
I think that this is a good approach. As @ephys mentioned we might even want to set the default to 3 until Temporal is ready to be used |
@WikiRik okay, that sounds good, I'll hold off for a bit and not run any migrations for now 😇 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Let's keep the possible change of the default for a future PR
Pull Request Checklist
Background
I'm working on upgrading Sequelize from 6 to the 7 alphas in a rather big application that uses Postgres as its main database. Its test suite includes a "schema drift" checker that compares the result of
sequelize.sync()
against the previous schema with migrations applied. When we upgraded to Sequelize 7, this script caught hundreds of drifts because Sequelize 7 provisions the auto-generatedcreatedAt
/updatedAt
/deletedAt
columns asTIMESTAMP(6) WITH TIME ZONE
, whereas with Sequelize 6 they came out asTIMESTAMP WITH TIME ZONE
because no explicit precision was specified.Reading up on the Postgres docs, it seems like the two type declarations mean the same, for all intents and purposes, also wrt. the SQL standard. That makes me think that the explicit precision slipped into #14505 by accident, so I suggest
changing it backadding an option to override it in order to to limit the amount of unnecessary churn that users will run into when upgrading Sequelize 🤗Description Of Change
Add a
defaultTimestampPrecision
option that can be specified per Sequelize instance.Todos