Migrate: Generate triggers for `@updatedAt`

Created on 10 Aug 2020  路  2Comments  路  Source: prisma/migrate

Problem

Currently, when I put the @updatedAt directive to a column on my model, it "only" makes the Prisma client update the column with this directive whenever the given model is updated.

However, when I edit the model in Prisma Studio / another Database GUI / or using a different query builder/ORM, the row does not get updated.

Suggested solution

The solution could be to generate triggers for the columns with the @updatedAt directive so that no matter the method used to edit the data in the DB the updatedAt column would get updated.

Alternatives

An alternative is to add the triggers to the DB manually

statuneeds-action teamigrations

All 2 comments

However, when I edit the model in Prisma Studio ... the row does not get updated.

Are you sure about that? Prisma Studio should have the same behavior as using Prisma Client directly.

@tomdohnal Thanks for taking the time to share your suggestion!

createdAt and updatedAt fields are populated by Prisma Client at runtime. Using triggers would be technically possible but has other disadvantages such as database compatibility. This is not something we are considering implementing at this time.

As @janpio indicated, Prisma Studio should also populate these fields with values. If you think this is not working as expected please feel free to open a GH issue in the prisma/prisma repo.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hamidb80 picture hamidb80  路  4Comments

julien1619 picture julien1619  路  4Comments

agryaznov picture agryaznov  路  3Comments

2013-11390 picture 2013-11390  路  3Comments

steebchen picture steebchen  路  3Comments