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

Add built-in support for ON UPDATE CURRENT_TIMESTAMP. #1163

Open
igalklebanov opened this issue Sep 30, 2024 · 0 comments · May be fixed by #1174
Open

Add built-in support for ON UPDATE CURRENT_TIMESTAMP. #1163

igalklebanov opened this issue Sep 30, 2024 · 0 comments · May be fixed by #1174
Labels
api Related to library's API enhancement New feature or request mysql Related to MySQL

Comments

@igalklebanov
Copy link
Member

Hey 👋

updated_at columns are very common. MySQL supports the ON UPDATE CURRENT_TIMESTAMP shortcut that makes the column value change to current date and time on every record update.

Currently, we don't have a built-in way that supports it.

We have an onUpdate method on the column definition builder, but it only supports foreign key actions as strings.

Users are forced to:

import { sql } from 'kysely'

.addColumn('updated_at', 'datetime', (cb) => cb.modifyEnd(sql`ON UPDATE CURRENT_TIMESTAMP`))

everywhere, this is not ideal.

The easiest would be to add 'CURRENT_TIMESTAMP' to onUpdate's argument type, and parse it differently at runtime - no foreign key related nodes.

Alternatively, we could introduce onUpdateCurrentTimestamp().

@igalklebanov igalklebanov added enhancement New feature or request mysql Related to MySQL api Related to library's API labels Sep 30, 2024
@austinwoon austinwoon linked a pull request Oct 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request mysql Related to MySQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant