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

db-migrate-pg

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

db-migrate-pg - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

167

index.js

@@ -8,3 +8,3 @@ var util = require('util');

var PgDriver = Base.extend({
init: function (connection, schema, intern) {
init: function(connection, schema, intern) {
this.log = intern.mod.log;

@@ -19,3 +19,3 @@ this.type = intern.mod.type;

startMigration: function (cb) {
startMigration: function(cb) {
if (!this.internals.notransactions) {

@@ -26,3 +26,3 @@ return this.runSql('BEGIN;').nodeify(cb);

endMigration: function (cb) {
endMigration: function(cb) {
if (!this.internals.notransactions) {

@@ -33,6 +33,6 @@ return this.runSql('COMMIT;').nodeify(cb);

createColumnDef: function (name, spec, options, tableName) {
createColumnDef: function(name, spec, options, tableName) {
// add support for datatype timetz, timestamptz
// https://www.postgresql.org/docs/9.5/static/datatype.html
spec.type = spec.type.replace(/^(time|timestamp)tz$/, function ($, type) {
spec.type = spec.type.replace(/^(time|timestamp)tz$/, function($, type) {
spec.timezone = true;

@@ -61,3 +61,3 @@ return type;

_translateSpecialDefaultValues: function (
_translateSpecialDefaultValues: function(
spec,

@@ -78,3 +78,3 @@ options,

mapDataType: function (str) {
mapDataType: function(str) {
switch (str) {

@@ -94,3 +94,3 @@ case 'json':

createDatabase: function (dbName, options, callback) {
createDatabase: function(dbName, options, callback) {
var spec = '';

@@ -106,3 +106,3 @@

dropDatabase: function (dbName, options, callback) {
dropDatabase: function(dbName, options, callback) {
var ifExists = '';

@@ -121,3 +121,3 @@

createSequence: function (sqName, options, callback) {
createSequence: function(sqName, options, callback) {
var spec = '';

@@ -137,3 +137,3 @@ var temp = '';

switchDatabase: function (options, callback) {
switchDatabase: function(options, callback) {
if (typeof options === 'object') {

@@ -154,3 +154,3 @@ if (typeof options.database === 'string') {

dropSequence: function (dbName, options, callback) {
dropSequence: function(dbName, options, callback) {
var ifExists = '';

@@ -173,3 +173,3 @@ var rule = '';

createMigrationsTable: function (callback) {
createMigrationsTable: function(callback) {
var options = {

@@ -191,3 +191,3 @@ columns: {

.then(
function (result) {
function(result) {
if (result && result.length > 0 && result[0].server_version_num) {

@@ -209,5 +209,5 @@ var version = result[0].server_version_num;

// not all DBs support server_version_num, fall back to server_version
function () {
function() {
return this.all('show server_version').then(
function (result) {
function(result) {
if (result && result.length > 0 && result[0].server_version) {

@@ -231,3 +231,3 @@ var version = result[0].server_version;

.then(
function (result) {
function(result) {
var searchPath;

@@ -257,3 +257,3 @@ var searchPathes = result[0].search_path.split(',');

.then(
function () {
function() {
return this.all(

@@ -268,3 +268,3 @@ "SELECT table_name FROM information_schema.tables WHERE table_name = '" +

.then(
function (result) {
function(result) {
if (result && result.length < 1) {

@@ -280,3 +280,3 @@ return this.createTable(this.internals.migrationTable, options);

createSeedsTable: function (callback) {
createSeedsTable: function(callback) {
var options = {

@@ -298,3 +298,3 @@ columns: {

.then(
function (result) {
function(result) {
if (result && result.length > 0 && result[0].version) {

@@ -314,3 +314,3 @@ var version = result[0].version;

.then(
function (result) {
function(result) {
var searchPath;

@@ -331,3 +331,3 @@

.then(
function () {
function() {
return this.all(

@@ -342,3 +342,3 @@ "SELECT table_name FROM information_schema.tables WHERE table_name = '" +

.then(
function (result) {
function(result) {
if (result && result.length < 1) {

@@ -354,3 +354,3 @@ return this.createTable(this.internals.seedTable, options);

createColumnConstraint: function (spec, options, tableName, columnName) {
createColumnConstraint: function(spec, options, tableName, columnName) {
var constraint = [];

@@ -400,3 +400,3 @@ var callbacks = [];

callbacks.push(
function (tableName, columnName, comment, callback) {
function(tableName, columnName, comment, callback) {
var sql = util.format(

@@ -420,3 +420,9 @@ "COMMENT on COLUMN %s.%s IS '%s'",

renameTable: function (tableName, newTableName, callback) {
renameTable: function(tableName, newTableName, callback) {
let options = {};
if (typeof callback === 'object') {
options = callback;
callback = null;
}
var sql = util.format(

@@ -430,3 +436,17 @@ 'ALTER TABLE "%s" RENAME TO "%s"',

removeColumn: function (tableName, columnName, callback) {
removeColumn: function(tableName, columnName, callback) {
let options = {};
if (typeof callback === 'object') {
options = callback;
callback = null;
}
if (options.columnStrategy === 'delay') {
return this.renameColumn(
tableName,
columnName,
options.passthrough.column
);
}
var sql = util.format(

@@ -441,3 +461,9 @@ 'ALTER TABLE "%s" DROP COLUMN "%s"',

renameColumn: function (tableName, oldColumnName, newColumnName, callback) {
renameColumn: function(tableName, oldColumnName, newColumnName, callback) {
let options = {};
if (typeof callback === 'object') {
options = callback;
callback = null;
}
var sql = util.format(

@@ -452,6 +478,12 @@ 'ALTER TABLE "%s" RENAME COLUMN "%s" TO "%s"',

changeColumn: function (tableName, columnName, columnSpec, callback) {
changeColumn: function(tableName, columnName, columnSpec, callback) {
let options = {};
if (typeof callback === 'object') {
options = callback;
callback = null;
}
return setNotNull.call(this);
function setNotNull () {
function setNotNull() {
var setOrDrop = columnSpec.notNull === true ? 'SET' : 'DROP';

@@ -468,3 +500,3 @@ var sql = util.format(

function setUnique (err) {
function setUnique(err) {
if (err) {

@@ -497,3 +529,3 @@ return Promise.reject(err);

function setDefaultValue (err) {
function setDefaultValue(err) {
if (err) {

@@ -530,3 +562,3 @@ return Promise.reject(err).nodeify(callback);

function setType () {
function setType() {
if (columnSpec.type !== undefined) {

@@ -537,6 +569,6 @@ var using =

: util.format(
'USING "%s"::%s',
columnName,
this.mapDataType(columnSpec.type)
);
'USING "%s"::%s',
columnName,
this.mapDataType(columnSpec.type)
);
var len = columnSpec.length

@@ -558,3 +590,3 @@ ? util.format('(%s)', columnSpec.length)

addForeignKey: function (
addForeignKey: function(
tableName,

@@ -572,3 +604,3 @@ referencedTableName,

var columns = Object.keys(fieldMapping);
var referencedColumns = columns.map(function (key) {
var referencedColumns = columns.map(function(key) {
return '"' + fieldMapping[key] + '"';

@@ -589,12 +621,19 @@ });

removeForeignKey: function (tableName, keyName, callback) {
var sql = util.format(
'ALTER TABLE "%s" DROP CONSTRAINT "%s"',
tableName,
keyName
);
removeForeignKey: function(tableName, keyName, callback) {
let options = {};
if (typeof callback === 'object') {
options = callback;
callback = null;
}
if (type)
var sql = util.format(
'ALTER TABLE "%s" DROP CONSTRAINT "%s"',
tableName,
keyName
);
return this.runSql(sql).nodeify(callback);
},
insert: function () {
insert: function() {
var index = 1;

@@ -606,3 +645,3 @@

arguments[index] = arguments[index].map(function (value) {
arguments[index] = arguments[index].map(function(value) {
return typeof value === 'string' ? value : JSON.stringify(value);

@@ -614,3 +653,3 @@ });

runSql: function () {
runSql: function() {
var callback;

@@ -644,4 +683,4 @@ var minLength = 1;

return new Promise(
function (resolve, reject) {
var prCB = function (err, data) {
function(resolve, reject) {
var prCB = function(err, data) {
return err ? reject(err) : resolve(data);

@@ -658,3 +697,3 @@ };

_getKV: function (table, key) {
_getKV: function(table, key) {
var sql =

@@ -669,3 +708,3 @@ 'SELECT * FROM ' +

all: function (...params) {
all: function(...params) {
let cb;

@@ -679,7 +718,7 @@ if (typeof params[params.length - 1] === 'function') {

return new Promise(
function (resolve, reject) {
var prCB = function (err, data) {
function(resolve, reject) {
var prCB = function(err, data) {
return err ? reject(err) : resolve(data);
};
params.push(function (err, result) {
params.push(function(err, result) {
prCB(err, result ? result.rows : result);

@@ -693,3 +732,3 @@ });

close: function (callback) {
close: function(callback) {
this.connection.end();

@@ -699,2 +738,12 @@ if (typeof callback === 'function') {

} else return Promise.resolve();
},
_meta: {
supports: {
// all legacy callbacks can be option objects
optionParam: true,
// support for column strategies for example on dropping not
// null columns
columnStrategies: true
}
}

@@ -705,3 +754,3 @@ });

exports.connect = function (config, intern, callback) {
exports.connect = function(config, intern, callback) {
if (config.native) {

@@ -714,3 +763,3 @@ pg = pg.native;

var db = config.db || new pg.Client(config);
db.connect(function (err) {
db.connect(function(err) {
if (err) {

@@ -717,0 +766,0 @@ callback(err);

{
"name": "db-migrate-pg",
"version": "1.0.0",
"version": "1.1.0",
"description": "A postgresql driver for db-migrate",

@@ -5,0 +5,0 @@ "main": "index.js",

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