简体   繁体   English

如何跟踪 model 更改 nodejs/postgresql

[英]How to track model changes nodejs/postgresql

I have a app perpetuating data in Postgresql/Express/Knex/Objection.我有一个应用程序在 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跟踪模型中的更改的方式,以便我可以管理和恢复类似于 rails 中的 paper_trail 或此端口以进行续集的版本: 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有什么我可以在 Knex/Objection 或数据库级别用于跟踪更改的东西吗

Answer: There is not any generic way to do it in Objection nor knex.回答:在 Objection 和 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.您需要设计您喜欢跟踪的更改类型并编写一些代码,例如 Model 钩子以反对如何跟踪更改。

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.实现它的一种方法是例如添加一个单独的表,其中所有跟踪的更改都写入例如 JSONB object 中,其中存储和索引更新的字段或旧值或类似的东西。 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这也可能对您有用:https://wiki.postgresql.org/wiki/Audit_trigger

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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