Have DB auto-update last_updated fields

In my DB backend, I have the repeating requirement to set created and updated fields. I know that mySQL can manage such fields automatically and I guess most other DBs will do likewise.

I understand that doctrine is used to abstract table schemata from various flavours of backend DBs.

Is there a simple way to configure doctrine such that auto-updating is done on the db side? I was thinking of making the proper definitions in the corresponding NC SimpleMigrationStep class and would like to avoid working with db events.

Related: is there a way to set CURRENT_TIMESTAMP as a DEFAULT value through doctrine?

I don’t know of any but that sounds like a very interesting concept.

I still don’t have a definitie answer. It seems a complicated thing to do unless you know which DB you have (there are ways to do it in mySQL, for instance).

The CREATED timestamp could be done purely in PHP by assigning the current datetime to the appropriate field in the constructor of the object in question.

DoctrineExtensions/timestampable.md at main · doctrine-extensions/DoctrineExtensions · GitHub and DoctrineExtensions/upgrade-v2.4-to-v3.0.md at main · doctrine-extensions/DoctrineExtensions · GitHub.

We may adapt some of those code to Nextcloud.

1 Like