node-pg-migrate
Advanced tools
Comparing version 5.5.0 to 5.5.1
# Change Log | ||
## [5.5.1](2020-08-18) | ||
### Fixed | ||
- Do not try to unlock DB if connection failed [#677](https://github.com/salsita/node-pg-migrate/pull/677) | ||
## [5.5.0](2020-08-10) | ||
@@ -4,0 +10,0 @@ |
@@ -8,2 +8,3 @@ import { ClientBase, ClientConfig, QueryArrayConfig, QueryConfig } from 'pg'; | ||
column(columnName: string, queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<any[]>; | ||
connected: () => boolean; | ||
addBeforeCloseListener: (listener: any) => number; | ||
@@ -10,0 +11,0 @@ close(): Promise<void>; |
@@ -5,17 +5,32 @@ "use strict"; | ||
const pg_1 = require("pg"); | ||
var ConnectionStatus; | ||
(function (ConnectionStatus) { | ||
ConnectionStatus["DISCONNECTED"] = "DISCONNECTED"; | ||
ConnectionStatus["CONNECTED"] = "CONNECTED"; | ||
ConnectionStatus["ERROR"] = "ERROR"; | ||
})(ConnectionStatus || (ConnectionStatus = {})); | ||
const db = (connection, logger = console) => { | ||
const isExternalClient = typeof connection === 'object' && 'query' in connection && typeof connection.query === 'function'; | ||
let clientActive = false; | ||
let connectionStatus = ConnectionStatus.DISCONNECTED; | ||
const client = isExternalClient ? connection : new pg_1.Client(connection); | ||
const beforeCloseListeners = []; | ||
const createConnection = () => new Promise((resolve, reject) => clientActive || isExternalClient | ||
? resolve() | ||
: client.connect((err) => { | ||
if (err) { | ||
logger.error(`could not connect to postgres: ${util_1.inspect(err)}`); | ||
return reject(err); | ||
} | ||
clientActive = true; | ||
return resolve(); | ||
})); | ||
const createConnection = () => new Promise((resolve, reject) => { | ||
if (isExternalClient || connectionStatus === ConnectionStatus.CONNECTED) { | ||
resolve(); | ||
} | ||
else if (connectionStatus === ConnectionStatus.ERROR) { | ||
reject(new Error('Connection already failed, do not try to connect again')); | ||
} | ||
else { | ||
client.connect((err) => { | ||
if (err) { | ||
connectionStatus = ConnectionStatus.ERROR; | ||
logger.error(`could not connect to postgres: ${util_1.inspect(err)}`); | ||
return reject(err); | ||
} | ||
connectionStatus = ConnectionStatus.CONNECTED; | ||
return resolve(); | ||
}); | ||
} | ||
}); | ||
const query = async (queryTextOrConfig, values) => { | ||
@@ -65,2 +80,3 @@ await createConnection(); | ||
column, | ||
connected: () => connectionStatus === ConnectionStatus.CONNECTED, | ||
addBeforeCloseListener: (listener) => beforeCloseListeners.push(listener), | ||
@@ -70,3 +86,3 @@ close: async () => { | ||
if (!isExternalClient) { | ||
clientActive = false; | ||
connectionStatus = ConnectionStatus.DISCONNECTED; | ||
client.end(); | ||
@@ -73,0 +89,0 @@ } |
@@ -185,7 +185,9 @@ "use strict"; | ||
finally { | ||
if (!options.noLock) { | ||
await unlock(db).catch((error) => logger.warn(error.message)); | ||
if (db.connected()) { | ||
if (!options.noLock) { | ||
await unlock(db).catch((error) => logger.warn(error.message)); | ||
} | ||
db.close(); | ||
} | ||
db.close(); | ||
} | ||
}; |
{ | ||
"name": "node-pg-migrate", | ||
"version": "5.5.0", | ||
"version": "5.5.1", | ||
"description": "Postgresql database migration management tool for node.js", | ||
@@ -56,8 +56,8 @@ "author": "Theo Ephraim", | ||
"@types/mkdirp": "1.0.1", | ||
"@types/mocha": "8.0.1", | ||
"@types/mocha": "8.0.2", | ||
"@types/proxyquire": "1.3.28", | ||
"@types/sinon": "9.0.4", | ||
"@types/sinon-chai": "3.2.4", | ||
"@typescript-eslint/eslint-plugin": "3.8.0", | ||
"@typescript-eslint/parser": "3.8.0", | ||
"@typescript-eslint/eslint-plugin": "3.9.0", | ||
"@typescript-eslint/parser": "3.9.0", | ||
"chai": "4.2.0", | ||
@@ -69,6 +69,6 @@ "chai-as-promised": "7.1.1", | ||
"dotenv": "8.2.0", | ||
"eslint": "7.6.0", | ||
"eslint": "7.7.0", | ||
"eslint-config-airbnb-base": "14.2.0", | ||
"eslint-config-prettier": "6.11.0", | ||
"eslint-import-resolver-typescript": "2.2.0", | ||
"eslint-import-resolver-typescript": "2.2.1", | ||
"eslint-plugin-import": "2.22.0", | ||
@@ -85,3 +85,3 @@ "eslint-plugin-prettier": "3.1.4", | ||
"rimraf": "3.0.2", | ||
"sinon": "9.0.2", | ||
"sinon": "9.0.3", | ||
"sinon-chai": "3.5.0", | ||
@@ -88,0 +88,0 @@ "ts-node": "8.10.2", |
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
286444
3455