Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-pg-migrate

Package Overview
Dependencies
Maintainers
3
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-pg-migrate - npm Package Compare versions

Comparing version 3.14.2 to 3.15.0

6

CHANGELOG.md
# Change Log
## [3.15.0](2019-01-28)
### Added
- Infering migration language [#391](https://github.com/salsita/node-pg-migrate/pull/391)
## [3.14.2](2018-12-04)

@@ -4,0 +10,0 @@

6

dist/db.js

@@ -113,7 +113,9 @@ "use strict";

return function close() {
function close() {
return _close.apply(this, arguments);
};
}
return close;
}()
};
};

@@ -23,17 +23,70 @@ "use strict";

const _require = require("./utils"),
getMigrationTableSchema = _require.getMigrationTableSchema;
getMigrationTableSchema = _require.getMigrationTableSchema,
promisify = _require.promisify;
const readdir = promisify(fs.readdir); // eslint-disable-line security/detect-non-literal-fs-filename
const lstat = promisify(fs.lstat); // eslint-disable-line security/detect-non-literal-fs-filename
const SEPARATOR = "_";
const loadMigrationFiles =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (dir, ignorePattern) {
const dirContent = yield readdir(`${dir}/`);
const files = yield Promise.all(dirContent.map(
/*#__PURE__*/
function () {
var _ref2 = _asyncToGenerator(function* (file) {
const stats = yield lstat(`${dir}/${file}`);
return stats.isFile() ? file : null;
});
return function (_x3) {
return _ref2.apply(this, arguments);
};
}()));
const filter = new RegExp(`^(${ignorePattern})$`); // eslint-disable-line security/detect-non-literal-regexp
return files.filter(i => i && !filter.test(i)).sort();
});
return function loadMigrationFiles(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
const getLastSuffix =
/*#__PURE__*/
function () {
var _ref3 = _asyncToGenerator(function* (dir, ignorePattern) {
try {
const files = yield loadMigrationFiles(dir, ignorePattern);
return files.length > 0 ? path.extname(files[files.length - 1]).substr(1) : undefined;
} catch (err) {
return undefined;
}
});
return function getLastSuffix(_x4, _x5) {
return _ref3.apply(this, arguments);
};
}();
module.exports = class Migration {
// class method that creates a new migration file by cloning the migration template
static create(name, directory, language) {
// ensure the migrations directory exists
mkdirp.sync(directory); // file name looks like migrations/1391877300255_migration-title.js
static create(name, directory, language, ignorePattern) {
return _asyncToGenerator(function* () {
// ensure the migrations directory exists
mkdirp.sync(directory);
const suffix = language || (yield getLastSuffix(directory, ignorePattern)) || "js"; // file name looks like migrations/1391877300255_migration-title.js
const newFile = `${directory}/${Date.now()}${SEPARATOR}${name}.${language}`; // copy the default migration template to the new file location
// eslint-disable-next-line security/detect-non-literal-fs-filename
const newFile = `${directory}/${Date.now()}${SEPARATOR}${name}.${suffix}`; // copy the default migration template to the new file location
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.createReadStream(path.resolve(__dirname, `./migration-template.${language}`) // eslint-disable-next-line security/detect-non-literal-fs-filename
).pipe(fs.createWriteStream(newFile));
return new Migration(newFile, directory);
fs.createReadStream(path.resolve(__dirname, `./migration-template.${suffix}`) // eslint-disable-next-line security/detect-non-literal-fs-filename
).pipe(fs.createWriteStream(newFile));
return new Migration(null, newFile);
})();
}

@@ -145,2 +198,3 @@

};
};
module.exports.loadMigrationFiles = loadMigrationFiles;

@@ -35,8 +35,4 @@ "use strict";

const PG_MIGRATE_LOCK_ID = 7241865325823964;
const readdir = promisify(fs.readdir); // eslint-disable-line security/detect-non-literal-fs-filename
const readFile = promisify(fs.readFile); // eslint-disable-line security/detect-non-literal-fs-filename
const lstat = promisify(fs.lstat); // eslint-disable-line security/detect-non-literal-fs-filename
const idColumn = "id";

@@ -46,3 +42,3 @@ const nameColumn = "name";

const loadMigrationFiles =
const loadMigrations =
/*#__PURE__*/

@@ -52,19 +48,5 @@ function () {

try {
const files = yield Promise.all((yield readdir(`${options.dir}/`)).map(
/*#__PURE__*/
function () {
var _ref2 = _asyncToGenerator(function* (file) {
const stats = yield lstat(`${options.dir}/${file}`);
return stats.isFile() ? file : null;
});
return function (_x4) {
return _ref2.apply(this, arguments);
};
}()));
const filter = new RegExp(`^(${options.ignorePattern})$`); // eslint-disable-line security/detect-non-literal-regexp
let shorthands = {};
return files.filter(i => i && !filter.test(i)).sort((f1, f2) => f1 < f2 // eslint-disable-line no-nested-ternary
? -1 : f1 > f2 ? 1 : 0).map(file => {
const files = yield Migration.loadMigrationFiles(options.dir, options.ignorePattern);
return files.map(file => {
const filePath = `${options.dir}/${file}`;

@@ -78,5 +60,7 @@ const actions = path.extname(filePath) === ".sql" ? // eslint-disable-next-line security/detect-non-literal-fs-filename

return function up(_x5) {
function up(_x4) {
return _up.apply(this, arguments);
};
}
return up;
}()

@@ -93,3 +77,3 @@ } : // eslint-disable-next-line global-require,import/no-dynamic-require,security/detect-non-literal-require

return function loadMigrationFiles(_x, _x2, _x3) {
return function loadMigrations(_x, _x2, _x3) {
return _ref.apply(this, arguments);

@@ -102,6 +86,6 @@ };

function () {
var _ref3 = _asyncToGenerator(function* (db) {
const _ref4 = yield db.query(`select pg_try_advisory_lock(${PG_MIGRATE_LOCK_ID}) as "lockObtained"`),
_ref4$rows = _slicedToArray(_ref4.rows, 1),
lockObtained = _ref4$rows[0];
var _ref2 = _asyncToGenerator(function* (db) {
const _ref3 = yield db.query(`select pg_try_advisory_lock(${PG_MIGRATE_LOCK_ID}) as "lockObtained"`),
_ref3$rows = _slicedToArray(_ref3.rows, 1),
lockObtained = _ref3$rows[0];

@@ -113,4 +97,4 @@ if (!lockObtained) {

return function lock(_x6) {
return _ref3.apply(this, arguments);
return function lock(_x5) {
return _ref2.apply(this, arguments);
};

@@ -122,3 +106,3 @@ }();

function () {
var _ref5 = _asyncToGenerator(function* (db, options) {
var _ref4 = _asyncToGenerator(function* (db, options) {
try {

@@ -147,4 +131,4 @@ const schema = getMigrationTableSchema(options);

return function ensureMigrationsTable(_x7, _x8) {
return _ref5.apply(this, arguments);
return function ensureMigrationsTable(_x6, _x7) {
return _ref4.apply(this, arguments);
};

@@ -156,3 +140,3 @@ }();

function () {
var _ref6 = _asyncToGenerator(function* (db, options) {
var _ref5 = _asyncToGenerator(function* (db, options) {
const schema = getMigrationTableSchema(options);

@@ -167,4 +151,4 @@ const migrationsTable = options.migrationsTable;

return function getRunMigrations(_x9, _x10) {
return _ref6.apply(this, arguments);
return function getRunMigrations(_x8, _x9) {
return _ref5.apply(this, arguments);
};

@@ -217,3 +201,3 @@ }();

function () {
var _ref7 = _asyncToGenerator(function* (options) {
var _ref6 = _asyncToGenerator(function* (options) {
const log = options.log || console.log;

@@ -241,6 +225,6 @@ const db = Db(options.databaseUrl, log);

const _ref8 = yield Promise.all([loadMigrationFiles(db, options, log), getRunMigrations(db, options)]),
_ref9 = _slicedToArray(_ref8, 2),
migrations = _ref9[0],
runNames = _ref9[1];
const _ref7 = yield Promise.all([loadMigrations(db, options, log), getRunMigrations(db, options)]),
_ref8 = _slicedToArray(_ref7, 2),
migrations = _ref8[0],
runNames = _ref8[1];

@@ -285,4 +269,4 @@ if (options.checkOrder) {

return function runner(_x11) {
return _ref7.apply(this, arguments);
return function runner(_x10) {
return _ref6.apply(this, arguments);
};

@@ -289,0 +273,0 @@ }();

@@ -14,14 +14,43 @@ /*

const MigrationBuilder = require("./migration-builder");
const { getMigrationTableSchema } = require("./utils");
const { getMigrationTableSchema, promisify } = require("./utils");
const readdir = promisify(fs.readdir); // eslint-disable-line security/detect-non-literal-fs-filename
const lstat = promisify(fs.lstat); // eslint-disable-line security/detect-non-literal-fs-filename
const SEPARATOR = "_";
const loadMigrationFiles = async (dir, ignorePattern) => {
const dirContent = await readdir(`${dir}/`);
const files = await Promise.all(
dirContent.map(async file => {
const stats = await lstat(`${dir}/${file}`);
return stats.isFile() ? file : null;
})
);
const filter = new RegExp(`^(${ignorePattern})$`); // eslint-disable-line security/detect-non-literal-regexp
return files.filter(i => i && !filter.test(i)).sort();
};
const getLastSuffix = async (dir, ignorePattern) => {
try {
const files = await loadMigrationFiles(dir, ignorePattern);
return files.length > 0
? path.extname(files[files.length - 1]).substr(1)
: undefined;
} catch (err) {
return undefined;
}
};
module.exports = class Migration {
// class method that creates a new migration file by cloning the migration template
static create(name, directory, language) {
static async create(name, directory, language, ignorePattern) {
// ensure the migrations directory exists
mkdirp.sync(directory);
const suffix =
language || (await getLastSuffix(directory, ignorePattern)) || "js";
// file name looks like migrations/1391877300255_migration-title.js
const newFile = `${directory}/${Date.now()}${SEPARATOR}${name}.${language}`;
const newFile = `${directory}/${Date.now()}${SEPARATOR}${name}.${suffix}`;

@@ -31,7 +60,7 @@ // copy the default migration template to the new file location

fs.createReadStream(
path.resolve(__dirname, `./migration-template.${language}`)
path.resolve(__dirname, `./migration-template.${suffix}`)
// eslint-disable-next-line security/detect-non-literal-fs-filename
).pipe(fs.createWriteStream(newFile));
return new Migration(newFile, directory);
return new Migration(null, newFile);
}

@@ -145,1 +174,3 @@

};
module.exports.loadMigrationFiles = loadMigrationFiles;

@@ -15,5 +15,3 @@ const path = require("path");

const readdir = promisify(fs.readdir); // eslint-disable-line security/detect-non-literal-fs-filename
const readFile = promisify(fs.readFile); // eslint-disable-line security/detect-non-literal-fs-filename
const lstat = promisify(fs.lstat); // eslint-disable-line security/detect-non-literal-fs-filename

@@ -24,41 +22,29 @@ const idColumn = "id";

const loadMigrationFiles = async (db, options, log) => {
const loadMigrations = async (db, options, log) => {
try {
const files = await Promise.all(
(await readdir(`${options.dir}/`)).map(async file => {
const stats = await lstat(`${options.dir}/${file}`);
return stats.isFile() ? file : null;
})
let shorthands = {};
const files = await Migration.loadMigrationFiles(
options.dir,
options.ignorePattern
);
const filter = new RegExp(`^(${options.ignorePattern})$`); // eslint-disable-line security/detect-non-literal-regexp
let shorthands = {};
return files
.filter(i => i && !filter.test(i))
.sort((f1, f2) =>
f1 < f2 // eslint-disable-line no-nested-ternary
? -1
: f1 > f2
? 1
: 0
)
.map(file => {
const filePath = `${options.dir}/${file}`;
const actions =
path.extname(filePath) === ".sql"
? // eslint-disable-next-line security/detect-non-literal-fs-filename
{ up: async pgm => pgm.sql(await readFile(filePath, "utf8")) }
: // eslint-disable-next-line global-require,import/no-dynamic-require,security/detect-non-literal-require
require(path.relative(__dirname, filePath));
shorthands = { ...shorthands, ...actions.shorthands };
return new Migration(
db,
filePath,
actions,
options,
{
...shorthands
},
log
);
});
return files.map(file => {
const filePath = `${options.dir}/${file}`;
const actions =
path.extname(filePath) === ".sql"
? // eslint-disable-next-line security/detect-non-literal-fs-filename
{ up: async pgm => pgm.sql(await readFile(filePath, "utf8")) }
: // eslint-disable-next-line global-require,import/no-dynamic-require,security/detect-non-literal-require
require(path.relative(__dirname, filePath));
shorthands = { ...shorthands, ...actions.shorthands };
return new Migration(
db,
filePath,
actions,
options,
{
...shorthands
},
log
);
});
} catch (err) {

@@ -204,3 +190,3 @@ throw new Error(`Can't get migration files: ${err.stack}`);

const [migrations, runNames] = await Promise.all([
loadMigrationFiles(db, options, log),
loadMigrations(db, options, log),
getRunMigrations(db, options)

@@ -207,0 +193,0 @@ ]);

{
"name": "node-pg-migrate",
"version": "3.14.2",
"version": "3.15.0",
"description": "Postgresql database migration management tool for node.js",

@@ -52,25 +52,25 @@ "author": "Theo Ephraim",

"devDependencies": {
"@babel/cli": "7.1.5",
"@babel/core": "7.1.6",
"@babel/plugin-proposal-object-rest-spread": "7.0.0",
"@babel/preset-env": "7.1.6",
"@babel/cli": "7.2.3",
"@babel/core": "7.2.2",
"@babel/plugin-proposal-object-rest-spread": "7.3.1",
"@babel/preset-env": "7.3.1",
"babel-eslint": "10.0.1",
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
"config": "3.0.0",
"config": "3.0.1",
"cross-env": "5.2.0",
"dotenv": "6.1.0",
"eslint": "5.9.0",
"dotenv": "6.2.0",
"eslint": "5.12.1",
"eslint-config-airbnb-base": "13.1.0",
"eslint-config-prettier": "3.3.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-prettier": "3.0.0",
"eslint-config-prettier": "4.0.0",
"eslint-plugin-import": "2.15.0",
"eslint-plugin-prettier": "3.0.1",
"eslint-plugin-security": "1.4.0",
"husky": "1.2.0",
"husky": "1.3.1",
"lint-staged": "8.1.0",
"mocha": "5.2.0",
"pg": "7.7.1",
"prettier": "1.15.3",
"pg": "7.8.0",
"prettier": "1.16.1",
"proxyquire": "2.1.0",
"sinon": "7.1.1",
"sinon": "7.2.3",
"sinon-chai": "3.3.0"

@@ -77,0 +77,0 @@ },

@@ -6,4 +6,5 @@ {

":automergeLinters",
"schedule:weekly"
"schedule:weekly",
"group:allNonMajor"
]
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc