https://github.com/jellyvision/sequelize-logbook
A plugin for adding a log book / revision history / audit / paper trail to a sequelize model.
https://github.com/jellyvision/sequelize-logbook
audit audit-log audit-logs history history-tracking logbook logging papertrail revision revision-history revisions sequelize sequelizejs versioning versions
Last synced: 3 months ago
JSON representation
A plugin for adding a log book / revision history / audit / paper trail to a sequelize model.
- Host: GitHub
- URL: https://github.com/jellyvision/sequelize-logbook
- Owner: Jellyvision
- License: mit
- Created: 2017-09-29T15:49:28.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-29T16:11:52.000Z (about 8 years ago)
- Last Synced: 2025-05-13T19:12:51.294Z (5 months ago)
- Topics: audit, audit-log, audit-logs, history, history-tracking, logbook, logging, papertrail, revision, revision-history, revisions, sequelize, sequelizejs, versioning, versions
- Language: JavaScript
- Size: 6.84 KB
- Stars: 4
- Watchers: 19
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sequelize-Logbook
A plugin for adding a log book / revision history / audit / [paper trail](https://en.wiktionary.org/wiki/paper_trail) to a sequelize model.
# 🎛 Usage
## When using the [models/index.js](https://github.com/sequelize/express-example/blob/master/models/index.js) `associate` pattern:
`my-model.js`
```javascript
const trackRevisions = require('sequelize-logbook')module.exports = function(sequelize, DataTypes) {
let MyModel = sequelize.define('MyModel', {
...
classMethods: {
...
associate: function(){
...
trackRevisions(MyModel)
}
}
})
}```
## General use
```javascript
const trackRevisions = require('sequelize-logbook')let MyModel = sequelize.define('MyModel', {...})
let AnotherModel = sequelize.define('AnotherModel', {...})
trackRevisions(MyModel)
trackRevisions(AnotherModel)```
## 🐲 whoDunnit / blame / author tracking.
SequelizeRevisions will look against the global sequelize object
for a whoDunnit key. If this key is present, it will save this value
as the author of the revision.
Otherwise, it'll fall back to process.env.NODE_ENV```javascript
const sequelize = new Sequelize(db, user, password, config)
sequelize.whoDunnit = 'yourUserString'
```# ⚠ Caveats
Revisions will **not** be automatically generated for instances created, deleted, or updated with **Bulk** actions
If you want revisions generated for Bulk actions, pass `individualHooks: true` as a sequelize option.# 🏗 Contributing 
## 📐 Tests
`npm run test`## ✂ Linting
`npm run prettier`# ✨ Inspired by
* [ssteffl's snippet](https://gist.github.com/ssteffl/f58ce60105c365a8d482)
* [PaperTrail](https://github.com/airblade/paper_trail)## Related:
This library is similar to these other packages, with the addition of:
1. whoDunnit / blame history
2. Unit tests! 📏* [sequelize-paper-trail](https://www.npmjs.com/package/sequelize-paper-trail) - ⛔ [empty unit tests](https://github.com/nielsgl/sequelize-paper-trail/blob/master/test/index.spec.js)
* [sequelize-temporal](https://github.com/bonaval/sequelize-temporal) - 👴 not maintained
* [sequelize-revisions](https://github.com/bkniffler/sequelize-revisions) - 🚫 no unit tests# License
Sequelize-logbook is [MIT licensed](./LICENSE]).