sequelize / sequelize/sequelize

Defining a default ON UPDATE behavior for models, such as ON UPDATE CURRENT_TIMESTAMP

Open
#5,561 13 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
30.4k
Forks
4.3k
Avg merge
1d 6h
Merged PRs (30d)
68

Description

I want tables created with the definitions below but I do not see how I can do that with Sequelize when these columns are automatically defined. This is also being done with a MySQL database.

The reason I want it defined in the database is because multiple apps use this database and not all are built with Sequelize. And I want to enforce these default values. Is there a way to have Sequelize create tables with the schema shown below? Or would an update after the tables are created be necessary to older these columns?

`createdAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

I am looking through the docs and I do not see how these columns would be created as I intend.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Start by locating Sequelize's automatic timestamp column definitions and MySQL table-generation path, then compare the generated schema with the requested createdAt and updatedAt definitions. Done means Sequelize can create the requested ON UPDATE CURRENT_TIMESTAMP behavior, with coverage for the relevant MySQL schema path.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, node.js
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.