Package that helps you track changes to your models, for auditing or versioning. See how a model looked at any stage in its life-cycle and also allows you to Record the user who created the version.
npm install --save sequelize-model-trail
Sequelize Model Trail assumes that you have already set up your Sequelize connection, for example, like this:
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password');
then adding Sequelize Model Trail is as easy as:
const ModelTrail = require('sequelize-model-trail').init(sequelize);
ModelTrail.enableAndLoadModelTrail();
which loads the Model Trail library, and the enableAndLoadModelTrail()
method sets up a revisions
table and Model.
Note: You need to Pass userId as options if you want to enable user tracking
Currently, there is only one step to enable user tracking, ie, recording the user who created a particular revision.
Model.update({
/* ... */
}, {
userId: user.id
}).then(() {
/* ... */
});
+----+-------+--------------------------------------+-----------+------------+---------------------+---------------------+--------+ | id | model | document | operation | documentId | createdAt | updatedAt | userId | +----+-------+--------------------------------------+-----------+------------+---------------------+---------------------+--------+ | 1 | users | {"id": [1, null], "name": ["Salman", null]} | create | 1 | 2022-08-22 01:17:34 | 2022-08-22 01:17:34 | NULL | +----+-------+--------------------------------------+-----------+------------+---------------------+---------------------+--------+ +----+-------+--------------------------------------+-----------+------------+---------------------+---------------------+--------+ | 2 | users | {"name": ["Salman Zafar", "Salman"]} | update | 1 | 2022-08-22 01:20:10 | 2022-08-22 01:20:10 | 1 | +----+-------+--------------------------------------+-----------+------------+---------------------+---------------------+--------+ +----+-------+--------------------------------------+-----------+------------+---------------------+---------------------+--------+ | 3 | users | {} | destroy | 1 | 2022-08-22 01:21:30 | 2022-08-22 01:21:30 | 1 | +----+-------+--------------------------------------+-----------+------------+---------------------+---------------------+--------+
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
© Salman Zafar – @salmanzafar949
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/salmanzafar949/sequelize-model-trail
Contributors: https://github.com/salmanzafar949/sequelize-paper-trail/graphs/contributors
- Specify Models for Model Trails
- UUID
- CUSTOM MODEL/TABLE NAME
- CUSTOM OPTIONS
If this project help you reduce time to develop, you can give me a cup of coffee :)
Please use:
-
GitHub's issue tracker
This project was inspired by: