
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
sequelize-historical
Advanced tools
Warning: this is a fork of sequelize-temporal that adds support for Sequelize 5.
Historical tables maintain historical versions of data. Modifying operations (UPDATE, DELETE) on these tables don't cause permanent changes to entries, but create new versions of them. Hence this might be used to:
Under the hood a history table with the same structure, but without constraints is created.
The normal singular/plural naming scheme in Sequelize is used:
modelName + HistorymodelName + Historiesnpm install sequelize-historical
sequelize-historicalvar Sequelize = require('sequelize');
var Historical = require('sequelize-historical');
Create a sequelize instance and your models, e.g.
var sequelize = new Sequelize('', '', '', {
dialect: 'sqlite',
storage: __dirname + '/.test.sqlite'
});
var User = Historical(sequelize.define('User'), sequelize);
The output of historical is its input model, so assigning it's output to your
Model is not necessary, hence it's just the lazy version of:
var User = sequelize.define('User', {.types.}, {.options.}); // Sequelize Docu
Historical(User, sequelize);
The default syntax for Historical is:
Historical(model, sequelizeInstance, options)
whereas the options are listed here (with default value).
{
/* runs the insert within the sequelize hook chain, disable
for increased performance without warranties */
blocking: true,
/* By default sequelize-historical persist only changes, and saves the previous state in the history table.
The "full" option saves all transactions into the historical database
(i.e. this includes the latest state.)
This allows to only query the hostory table to get the full history of an entity.
*/
full: false
@See: https://wiki.postgresql.org/wiki/SQL2011Temporal
History table stores historical versions of rows, which are inserted by triggers on every modifying operation executed on current table. It has the same structure and indexes as current table, but it doesn’t have any constraints. History tables are insert only and creator should prevent other users from executing updates or deletes by correct user rights settings. Otherwise the history can be violated.
Triggers for storing old versions of rows to history table are inspired by referential integrity triggers. They are fired for each row before UPDATE and DELETE (within the same transaction)
If you only use Postgres, you might want to have a look at the Temporal Table extension.
The MIT License (MIT)
Copyright (c) 2015 BonaVal
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Historical tables for Sequelize
We found that sequelize-historical demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.