Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@rematter/sequelize-paranoid-delete
Advanced tools
Readme
sequelize-paranoid-delete enables onDelete when using paranoid mode in sequelize
The following example uses a MySql database through sequelize and persists the migration data in the database itself through the sequelize storage.
// index.js
const { Sequelize } = require('sequelize');
const { Umzug, SequelizeStorage } = require('umzug');
const { queryInterfaceDecorator } = require('sequelize-paranoid-delete');
const sequelize = new Sequelize({ dialect: 'mysql', storage: './db.mysql' });
const umzug = new Umzug({
migrations: { glob: 'migrations/*.js' },
// as simple as the following line
context: queryInterfaceDecorator(sequelize.getQueryInterface()),
storage: new SequelizeStorage({ sequelize }),
logger: console,
});
// migrations/00_initial.js
const { Sequelize } = require('sequelize');
async function up({ context: queryInterface }) {
await queryInterface.createTable('resources', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
userId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id',
},
// here we specify the behavior
onDelete: 'PARANOID CASCADE',
}
createdAt: {
type: Sequelize.DATE,
allowNull: false,
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
},
deletedAt: {
type: Sequelize.DATE,
allowNull: true,
},
});
}
This is going to create a trigger in the users table, when a user gets "deleted", the resource will be marked as deleted as well.
If the table was already created, you can use addColumn as well.
const { Sequelize } = require('sequelize');
async function up({ context: queryInterface }) {
await queryInterface.addColumn('resources', 'userId', {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id',
},
// here we specify the behavior
onDelete: 'PARANOID CASCADE',
});
}
sequelize-paranoid-delete is available on npm by specifying the correct tag:
npm install @rematter/sequelize-paranoid-delete
OR
yarn add @rematter/sequelize-paranoid-delete
Put configuration options in a file named .spdrc
in your working directory.
The expected structure of the file is the following:
{
"dbname": "",
"schema": "",
"username": "",
"password": "",
"host": "",
"port": "",
"dialect": "mysql",
"allowListTables": null,
"denyListTables": null,
"tenantColumns": null
}
Allow list tables, deny list tables and tenant columns are optional.
First two are for configuring which tables you DO want to scan or you do NOT want to scan (specify only one).
Tenant columns is to prevent scanning relations between tenant foreign keys.
npx sequelize-paranoid-delete
yarn node --inspect-brk ./node_modules/.bin/ts-mocha -p lib.tsconfig.json src/**/*.test.ts
See the LICENSE file
FAQs
sequelize-paranoid-delete enables onDelete when using paranoid mode
We found that @rematter/sequelize-paranoid-delete demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.