简体   繁体   中英

How to track model changes nodejs/postgresql

I have a app perpetuating data in Postgresql/Express/Knex/Objection. I am looking for. way t track changes in my models, so that I can manage and revert versions similar to paper_trail in rails or this port for sequelize: https://github.com/nielsgl/sequelize-paper-trail

Is there something I could use for this in Knex/Objection or at the db level to track changes

Answer: There is not any generic way to do it in Objection nor knex.

Random rambling:

You need to design what kind of changes you like to track and write some code for example to Model hooks in objection how to track the changes.

One way to implement it would be for example by adding a separate table where all the tracked changes are written for example in JSONB object where updated fields or old values are stored and indexed or something like that. I'm pretty sure you don't want to add tracking of all the data in the database, since it will blow up the DB size very fast.

Anyways implementation depends what it is actually why you like or need to track the data and what are actual use cases that you need to support.

Also this might work for you: https://wiki.postgresql.org/wiki/Audit_trigger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM