website icon indicating copy to clipboard operation
website copied to clipboard

Consequences of disabling timestamps

Open Hackatosh opened this issue 3 years ago • 2 comments

Issue Creation Checklist

[X] I have read the contribution guidelines

Issue Description

What was unclear/insufficient/not covered in the documentation

The consequences of disabling the timestamps (createdAt / updatedAt) are not very clear in the documentation : https://sequelize.org/docs/v6/core-concepts/model-basics/

If possible: Provide some suggestion on how we can enhance the docs

Make clear what is the impact of disabling the timestamps. Are they used internally by Sequelize for any purpose ? Or are we completely free to disable them ?

Additional context

Hello ! I have a use case where I need to track the last modification time of every row of a table, which can be modified through Sequelize and through SQL queries executed directly on the DB. I'd like to store this time in the updated_at column. In order for this time to be accurate, I'd like to disable Sequelize's automatic update on updated_at column and add a SQL trigger, but I am not sure of the impact of this action.

Also, if I use those parameters for the Model init :

{
  sequelize,
  timestamps: true,
  updatedAt: false
}

Will the column updated still be present but without the automatic update from Sequelize ? Or am I mistaken ?

Hackatosh avatar Apr 21 '22 14:04 Hackatosh

createdAt and updatedAt are not used for anything by sequelize itself. It's safe to disable them, and add your own.

deletedAt is necessary if the model is paranoid

ephys avatar Apr 21 '22 14:04 ephys

Thank you very much for the quick answer ! 😄

Hackatosh avatar Apr 21 '22 14:04 Hackatosh