You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mysql-migrate-cli

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-migrate-cli - npm Package Compare versions

Comparing version

to
0.1.0

1

index.js

@@ -17,3 +17,2 @@ /* IMPORTS */

if (options._.includes('create')) {

@@ -20,0 +19,0 @@ create(options);

const fs = require('fs');
const path = require('path');
module.exports = options => {

@@ -6,0 +5,0 @@ const name = `${Date.now()}-migration.js`;

52

lib/db.js
const path = require('path');
const mysql = require('mysql');
module.exports = configPath => {

@@ -10,18 +9,30 @@ const dir = process.cwd();

const query = query => new Promise((resolve, reject) => {
connection.beginTransaction(error => {
const transaction = query => new Promise((resolve, reject) => {
query = `
DROP PROCEDURE IF EXISTS sp_fail;
CREATE PROCEDURE sp_fail()
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
START TRANSACTION;
${query};
COMMIT;
END;
CALL sp_fail();
DROP PROCEDURE sp_fail;
`.replace(/;\n*\s*;|;\r*\n*\s*;/gm, ';');
connection.query(query, (error, result) => {
if (error) {
reject(error);
connection.query('ROLLBACK;', (err, result) => {
reject(err || error);
});
} else {
connection.query(query, (error, result) => {
if (error) {
connection.rollback(() => reject(error));
connection.query('COMMIT;', (err, result) => {
if (err) {
reject(err);
} else {
connection.commit(error => {
if (error) {
connection.rollback(() => reject(error));
} else {
resolve(result);
}
});
resolve(result);
}

@@ -34,3 +45,14 @@ });

return {
query,
transaction,
query (query) {
return new Promise((resolve, reject) => {
connection.query(query, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
},
end () {

@@ -37,0 +59,0 @@ connection.end();

const path = require('path');
const db = require('./db');
module.exports = async options => {

@@ -26,5 +25,5 @@ try {

await connection.query(`
await connection.transaction(`
${file.down};
DELETE FROM ${options.table} WHERE file = '${migration}';
${file.down}
`);

@@ -31,0 +30,0 @@

@@ -5,3 +5,2 @@ const fs = require('fs');

module.exports = async options => {

@@ -32,5 +31,5 @@ try {

await connection.query(`
await connection.transaction(`
${file.up};
INSERT INTO ${options.table} (file) VALUES ('${migration}');
${file.up}
`);

@@ -37,0 +36,0 @@

{
"name": "mysql-migrate-cli",
"version": "0.0.2",
"version": "0.1.0",
"description": "Migrations tool for MYSQL db",

@@ -36,3 +36,3 @@ "main": "index.js",

"scripts": {
"lint": "eslint index.js"
"lint": "eslint index.js ./lib/**"
},

@@ -39,0 +39,0 @@ "engines": {

@@ -0,0 +0,0 @@ # mysql-migrate-cli

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet