Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
larvitdbmigration
Advanced tools
This is used to keep track of the database structure, content etc, and update it when need be via deploys.
Supported databases:
A table/index by default called db_version will be created, containing a single integer.
Scripts will be placed by default in process.cwd()/dbmigration/.js
Each migration script will be ran, and the db_version increased, until no more migration scripts exists.
npm i larvitdbmigration
In your application startup script, do something like this:
'use strict';
const DbMigration = require('larvitdbmigration');
const Db = require('larvitdb');
const dbDriver = new Db({
host: '127.0.0.1',
user: 'foo',
password: 'bar',
database: 'baz'
});
const dbMigration = new DbMigration({
dbType: 'mariadb',
dbDriver,
tableName: 'db_version', // Optional - used as index name for elasticsearch
migrationScriptPath: './dbmigration', // Optional
log // Optional, will use log.silly(), log.debug(), log.verbose(), log.info(), log.warn() and log.error() if given.
});
dbMigration.run().then(() => {
// Now database is migrated and ready for use!
}).catch(err => {
throw err;
});
'use strict';
const DbMigration = require('larvitdbmigration');
const dbMigration = new DbMigration({
dbType: 'elasticsearch',
url: 'http://127.0.0.1:9200',
indexName: 'db_version', // Optional
migrationScriptPath: './dbmigration', // Optional
axios // Optional, will use default axios instance if not specified.
log // Optional, will use log.silly(), log.debug(), log.verbose(), log.info(), log.warn() and log.error() if given.
});
dbMigration.run().then(() => {
// Now database is migrated and ready for use!
}).catch(err => {
throw err;
});
Lets say the current database have a table like this:
CREATE TABLE bloj (nisse int(11));
And in the next deploy we'd like to change the column name "nisse" to "hasse". For this you can do one of two methods:
Create the file process.cwd()/migrationScriptPath/1.js with this content:
'use strict';
// Always make the function async (or explicitly return a promise, see elasticsearch example below)
exports = module.exports = async function (options) {
const {db} = options;
await db.query('ALTER TABLE bloj CHANGE nisse hasse int(11);');
};
Create the file process.cwd()/migrationScriptPath/1.js with this content:
'use strict';
const axios = require('axios');
exports = module.exports = async function (options) {
const {url, log} = options;
log.info('Some script-specific logging');
await axios.put(`${url}/some_index/_mapping`, {
properties: {
names: {
type: 'string',
position_increment_gap: 100
}
}
});
};
IMPORTANT! SQL files will be ignored if a .js file exists.
Create the file process.cwd()/migrationScriptPath/1.sql with this content:
ALTER TABLE bloj CHANGE nisse hasse int(11);
Tadaaa! Now this gets done once and the version will be bumped to 1. If you then create a script named "2.js" or "2.sql" you might guess what happends. :)
FAQs
node.js database migration tool
The npm package larvitdbmigration receives a total of 631 weekly downloads. As such, larvitdbmigration popularity was classified as not popular.
We found that larvitdbmigration demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.