db-migrate-pg
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -0,1 +1,10 @@ | ||
## [0.5.1](https://github.com/db-migrate/pg/compare/v0.5.0...v0.5.1) (2019-05-13) | ||
### Bug Fixes | ||
* **addForeignKey:** pass joined strings to `util.format` ([21cbfe5](https://github.com/db-migrate/pg/commit/21cbfe5)) | ||
<a name="0.5.0"></a> | ||
@@ -2,0 +11,0 @@ # [0.5.0](https://github.com/db-migrate/pg/compare/v0.4.0...v0.5.0) (2019-02-11) |
114
index.js
@@ -7,6 +7,4 @@ var util = require('util'); | ||
var internals = {}; | ||
var PgDriver = Base.extend({ | ||
init: function(connection, schema, intern) { | ||
init: function (connection, schema, intern) { | ||
this.log = intern.mod.log; | ||
@@ -21,3 +19,3 @@ this.type = intern.mod.type; | ||
startMigration: function(cb) { | ||
startMigration: function (cb) { | ||
if (!this.internals.notransactions) { | ||
@@ -28,3 +26,3 @@ return this.runSql('BEGIN;').nodeify(cb); | ||
endMigration: function(cb) { | ||
endMigration: function (cb) { | ||
if (!this.internals.notransactions) { | ||
@@ -35,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; | ||
@@ -63,3 +61,3 @@ return type; | ||
_translateSpecialDefaultValues: function( | ||
_translateSpecialDefaultValues: function ( | ||
spec, | ||
@@ -80,3 +78,3 @@ options, | ||
mapDataType: function(str) { | ||
mapDataType: function (str) { | ||
switch (str) { | ||
@@ -96,3 +94,3 @@ case 'json': | ||
createDatabase: function(dbName, options, callback) { | ||
createDatabase: function (dbName, options, callback) { | ||
var spec = ''; | ||
@@ -108,3 +106,3 @@ | ||
dropDatabase: function(dbName, options, callback) { | ||
dropDatabase: function (dbName, options, callback) { | ||
var ifExists = ''; | ||
@@ -123,3 +121,3 @@ | ||
createSequence: function(sqName, options, callback) { | ||
createSequence: function (sqName, options, callback) { | ||
var spec = ''; | ||
@@ -139,3 +137,3 @@ var temp = ''; | ||
switchDatabase: function(options, callback) { | ||
switchDatabase: function (options, callback) { | ||
if (typeof options === 'object') { | ||
@@ -156,3 +154,3 @@ if (typeof options.database === 'string') { | ||
dropSequence: function(dbName, options, callback) { | ||
dropSequence: function (dbName, options, callback) { | ||
var ifExists = ''; | ||
@@ -175,3 +173,3 @@ var rule = ''; | ||
createMigrationsTable: function(callback) { | ||
createMigrationsTable: function (callback) { | ||
var options = { | ||
@@ -193,3 +191,3 @@ columns: { | ||
.then( | ||
function(result) { | ||
function (result) { | ||
if (result && result.length > 0 && result[0].server_version_num) { | ||
@@ -211,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) { | ||
@@ -233,3 +231,3 @@ var version = result[0].server_version; | ||
.then( | ||
function(result) { | ||
function (result) { | ||
var searchPath; | ||
@@ -259,3 +257,3 @@ var searchPathes = result[0].search_path.split(','); | ||
.then( | ||
function() { | ||
function () { | ||
return this.all( | ||
@@ -270,3 +268,3 @@ "SELECT table_name FROM information_schema.tables WHERE table_name = '" + | ||
.then( | ||
function(result) { | ||
function (result) { | ||
if (result && result && result.length < 1) { | ||
@@ -282,3 +280,3 @@ return this.createTable(this.internals.migrationTable, options); | ||
createSeedsTable: function(callback) { | ||
createSeedsTable: function (callback) { | ||
var options = { | ||
@@ -300,3 +298,3 @@ columns: { | ||
.then( | ||
function(result) { | ||
function (result) { | ||
if (result && result && result.length > 0 && result[0].version) { | ||
@@ -316,3 +314,3 @@ var version = result[0].version; | ||
.then( | ||
function(result) { | ||
function (result) { | ||
var searchPath; | ||
@@ -333,3 +331,3 @@ | ||
.then( | ||
function() { | ||
function () { | ||
return this.all( | ||
@@ -344,3 +342,3 @@ "SELECT table_name FROM information_schema.tables WHERE table_name = '" + | ||
.then( | ||
function(result) { | ||
function (result) { | ||
if (result && result && result.length < 1) { | ||
@@ -356,3 +354,3 @@ return this.createTable(this.internals.seedTable, options); | ||
createColumnConstraint: function(spec, options, tableName, columnName) { | ||
createColumnConstraint: function (spec, options, tableName, columnName) { | ||
var constraint = []; | ||
@@ -402,3 +400,3 @@ var callbacks = []; | ||
callbacks.push( | ||
function(tableName, columnName, comment, callback) { | ||
function (tableName, columnName, comment, callback) { | ||
var sql = util.format( | ||
@@ -422,3 +420,3 @@ "COMMENT on COLUMN %s.%s IS '%s'", | ||
renameTable: function(tableName, newTableName, callback) { | ||
renameTable: function (tableName, newTableName, callback) { | ||
var sql = util.format( | ||
@@ -432,3 +430,3 @@ 'ALTER TABLE "%s" RENAME TO "%s"', | ||
removeColumn: function(tableName, columnName, callback) { | ||
removeColumn: function (tableName, columnName, callback) { | ||
var sql = util.format( | ||
@@ -443,3 +441,3 @@ 'ALTER TABLE "%s" DROP COLUMN "%s"', | ||
renameColumn: function(tableName, oldColumnName, newColumnName, callback) { | ||
renameColumn: function (tableName, oldColumnName, newColumnName, callback) { | ||
var sql = util.format( | ||
@@ -454,6 +452,6 @@ 'ALTER TABLE "%s" RENAME COLUMN "%s" TO "%s"', | ||
changeColumn: function(tableName, columnName, columnSpec, callback) { | ||
changeColumn: function (tableName, columnName, columnSpec, callback) { | ||
return setNotNull.call(this); | ||
function setNotNull() { | ||
function setNotNull () { | ||
var setOrDrop = columnSpec.notNull === true ? 'SET' : 'DROP'; | ||
@@ -470,3 +468,3 @@ var sql = util.format( | ||
function setUnique(err) { | ||
function setUnique (err) { | ||
if (err) { | ||
@@ -499,3 +497,3 @@ return Promise.reject(err); | ||
function setDefaultValue(err) { | ||
function setDefaultValue (err) { | ||
if (err) { | ||
@@ -532,3 +530,3 @@ return Promise.reject(err).nodeify(callback); | ||
function setType() { | ||
function setType () { | ||
if (columnSpec.type !== undefined) { | ||
@@ -539,6 +537,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 | ||
@@ -560,3 +558,3 @@ ? util.format('(%s)', columnSpec.length) | ||
addForeignKey: function( | ||
addForeignKey: function ( | ||
tableName, | ||
@@ -574,3 +572,3 @@ referencedTableName, | ||
var columns = Object.keys(fieldMapping); | ||
var referencedColumns = columns.map(function(key) { | ||
var referencedColumns = columns.map(function (key) { | ||
return '"' + fieldMapping[key] + '"'; | ||
@@ -582,5 +580,5 @@ }); | ||
keyName, | ||
this.quoteDDLArr(columns), | ||
this.quoteDDLArr(columns).join(', '), | ||
referencedTableName, | ||
referencedColumns, | ||
referencedColumns.join(', '), | ||
rules.onDelete || 'NO ACTION', | ||
@@ -592,3 +590,3 @@ rules.onUpdate || 'NO ACTION' | ||
removeForeignKey: function(tableName, keyName, callback) { | ||
removeForeignKey: function (tableName, keyName, callback) { | ||
var sql = util.format( | ||
@@ -602,3 +600,3 @@ 'ALTER TABLE "%s" DROP CONSTRAINT "%s"', | ||
insert: function() { | ||
insert: function () { | ||
var index = 1; | ||
@@ -610,3 +608,3 @@ | ||
arguments[index] = arguments[index].map(function(value) { | ||
arguments[index] = arguments[index].map(function (value) { | ||
return typeof value === 'string' ? value : JSON.stringify(value); | ||
@@ -618,3 +616,3 @@ }); | ||
runSql: function() { | ||
runSql: function () { | ||
var callback; | ||
@@ -648,4 +646,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); | ||
@@ -662,3 +660,3 @@ }; | ||
all: function() { | ||
all: function () { | ||
var params = arguments; | ||
@@ -669,8 +667,8 @@ | ||
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); | ||
}; | ||
this.connection.query(params[0], function(err, result) { | ||
this.connection.query(params[0], function (err, result) { | ||
prCB(err, result ? result.rows : result); | ||
@@ -682,3 +680,3 @@ }); | ||
close: function(callback) { | ||
close: function (callback) { | ||
this.connection.end(); | ||
@@ -693,5 +691,3 @@ if (typeof callback === 'function') { | ||
exports.connect = function(config, intern, callback) { | ||
internals = intern; | ||
exports.connect = function (config, intern, callback) { | ||
if (config.native) { | ||
@@ -704,3 +700,3 @@ pg = pg.native; | ||
var db = config.db || new pg.Client(config); | ||
db.connect(function(err) { | ||
db.connect(function (err) { | ||
if (err) { | ||
@@ -707,0 +703,0 @@ callback(err); |
{ | ||
"name": "db-migrate-pg", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "A postgresql driver for db-migrate", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26878
587