sequelize / sequelize/sequelize
Mariadb migration can not create nullable timestamp column
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
Issue Creation Checklist
[x] I have read the contribution guidelines
Bug Description
Although for other datatypes, such a varchar, the default for MariaDb is Allow Null is true, but for timestamps it is false and it is handled differently, see the documentation and more docs here But is says there
This automatic initialization for NULL values can also be explicitly disabled for a column that uses the TIMESTAMP data type by specifying the NULL attribute for the column. In this case, if the column's value is set to NULL, then the column's value will actually be set to NULL.
One should therefore be able to specify when creating a timestamp column that it should be nullable, like this.
up: (queryInterface, Sequelize) => {
queryInterface.addColumn("account", "created_at", {
type: "TIMESTAMP",
allowNull: true,
}),
}
What do you expect to happen?
That should run the following query: (Note the NULL)
ALTER TABLE `account` ADD `created_at` TIMESTAMP NULL;
What is actually happening?
It is running this instead: (Note the NULL is missing)
ALTER TABLE `account` ADD `created_at` TIMESTAMP;
Additional context
This is a problem, because I want to add this field to an existing table, and if I don't make it nullable, it will insert the current timestamp into each existing row, (as mentioned in documentation linked above).
I can do it like this, but I believe it is still a bug.
queryInterface.sequelize.query(
"ALTER TABLE `account` ADD `created_at` TIMESTAMP NULL;",
)
Environment
- Sequelize version: 6.5.0
- Node.js version: 16.13.2
Bug Report Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s): Mariadb
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the queryInterface.addColumn entry point using the MariaDB example in the issue, then trace how its column definition becomes ALTER TABLE SQL. Reproduce the migration and verify that allowNull: true produces the expected TIMESTAMP NULL output without changing other dialect behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mariadb, node.js
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100