Replies: 4 comments 5 replies
-
|
I've been playing with proxies for a while now, you could probably proxy prisma create update delete to generate a snapshot of the record before changing it. If you keep a versions table with the ID, modelname, date and a jsonb column with the serialized record you'll be able to go back in time. This is obviously naive, because you'll have to deal with other things like relationships.. But it could give you something to start with. I had it in my plans to make something like this |
Beta Was this translation helpful? Give feedback.
-
|
It's not exactly what you are looking for, but what I am currently doing is to have a the check for an existing interaction is probably not needed, but due to my setup I need to add the middleware inside the context creation, which (probably only in dev) causes it to be created multiple times the code is inspired by: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/middleware/soft-delete-middleware |
Beta Was this translation helpful? Give feedback.
-
|
You could also go with an update trigger and create a separate history table for each table you already have. Your update table could have a created_at and content jsonb column where the update trigger would create a new row for each update. This way you could go back in time as well. |
Beta Was this translation helpful? Give feedback.
-
|
So I've learned that the domain of this discussion is called Temporal tables (I've amended the title to reflect this). Apparently this was an Oracle exclusive feature for a while but MS SQL has had it since SQL Server 2016. From my search, it seems PostgreSQL doesn't have this feature on its roadmap. I won't list all the links I've visited but I'll just leave this one as it very succinctly describes what I'm after (just search for the topic, plenty of articles and videos). EDIT: The above statement describes a bitemporal database (the holy grail). Most implementations are "just" System-Versioned Temporal Tables |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a requirement to keep track of all changes made to the data in my app.
For example, user details changes (email, phone number, name, etc...). All the old data should be kept but the app should only show the latest version. We currently keep audit logs of such things and have report pages that allow users to look through the old data. Going forward, I'd like to implement a time travel feature that would allow users to set a date filter, which would put the app in a read-only mode and show you what the app would have looked like on that date.
Here's an example (say
atis a date field).Old data
New Data
How would it work
Ideas?
I think that PostgreSQL triggers might be the way to go but not sure where to start. I'd appreciate if someone could could point me in the right direction
Beta Was this translation helpful? Give feedback.
All reactions