From: Justin Wind Date: Mon, 7 Apr 2025 19:39:30 +0000 (-0700) Subject: scrub verbose types from multiResponse logs X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=11dfc81724134457299c7d5dd96a0a3a938f3ba8;p=squeep-db-helper scrub verbose types from multiResponse logs --- diff --git a/lib/postgres-creator.js b/lib/postgres-creator.js index 88fa66c..34e28b1 100644 --- a/lib/postgres-creator.js +++ b/lib/postgres-creator.js @@ -72,6 +72,20 @@ const PostgresCreator = (Abstract) => { } + /** + * Remove noisy _types from results. + * @param {object[]} results multiResult response + * @returns {object[]} scrubbed results + */ + static _multiResultLog(results) { + const logResults = structuredClone(results); + for (const result of logResults) { + delete result._types; + } + return logResults; + } + + async _tableExists(tableName, schema) { if (schema) { return this.db.oneOrNone('SELECT table_name FROM information_schema.tables WHERE table_name=$(tableName) AND table_schema=$(schema)', { tableName, schema }); @@ -115,7 +129,7 @@ COMMIT;`); let metaExists = await this._tableExists(metaVersionTable, this.pgSchema); if (!metaExists) { const results = await this._createMetaVersionTable(); - this.logger.debug(_scope, 'created meta version table', { results }); + this.logger.debug(_scope, 'created meta version table', { results: this.constructor._multiResultLog(results) }); metaExists = await this._tableExists(metaVersionTable, this.pgSchema); /* istanbul ignore if */ if (!metaExists) { @@ -132,7 +146,7 @@ COMMIT;`); const fPath = path.join(sqlPath, 'sql', 'schema', v, 'apply.sql'); const migrationSql = _queryFile(fPath); const results = await this.db.multiResult(migrationSql); - this.logger.debug(_scope, 'executed migration sql', { version: v, results }); + this.logger.debug(_scope, 'executed migration sql', { version: v, results: this.constructor._multiResultLog(results) }); this.logger.info(_scope, 'applied migration', { version: v }); } } diff --git a/test/data/postgres.js b/test/data/postgres.js new file mode 100644 index 0000000..e7f79fa --- /dev/null +++ b/test/data/postgres.js @@ -0,0 +1,164 @@ +'use strict'; + +module.exports = { + multiResultResponse: [ + { + "command": "BEGIN", + "rowCount": null, + "oid": null, + "rows": [], + "fields": [], + "_types": { + "_types": { + "arrayParser": {}, + "builtins": { + "BOOL": 16, + "BYTEA": 17, + "CHAR": 18, + "INT8": 20, + "INT2": 21, + "INT4": 23, + "REGPROC": 24, + "TEXT": 25, + "OID": 26, + "TID": 27, + "XID": 28, + "CID": 29, + "JSON": 114, + "XML": 142, + "PG_NODE_TREE": 194, + "SMGR": 210, + "PATH": 602, + "POLYGON": 604, + "CIDR": 650, + "FLOAT4": 700, + "FLOAT8": 701, + "ABSTIME": 702, + "RELTIME": 703, + "TINTERVAL": 704, + "CIRCLE": 718, + "MACADDR8": 774, + "MONEY": 790, + "MACADDR": 829, + "INET": 869, + "ACLITEM": 1033, + "BPCHAR": 1042, + "VARCHAR": 1043, + "DATE": 1082, + "TIME": 1083, + "TIMESTAMP": 1114, + "TIMESTAMPTZ": 1184, + "INTERVAL": 1186, + "TIMETZ": 1266, + "BIT": 1560, + "VARBIT": 1562, + "NUMERIC": 1700, + "REFCURSOR": 1790, + "REGPROCEDURE": 2202, + "REGOPER": 2203, + "REGOPERATOR": 2204, + "REGCLASS": 2205, + "REGTYPE": 2206, + "UUID": 2950, + "TXID_SNAPSHOT": 2970, + "PG_LSN": 3220, + "PG_NDISTINCT": 3361, + "PG_DEPENDENCIES": 3402, + "TSVECTOR": 3614, + "TSQUERY": 3615, + "GTSVECTOR": 3642, + "REGCONFIG": 3734, + "REGDICTIONARY": 3769, + "JSONB": 3802, + "REGNAMESPACE": 4089, + "REGROLE": 4096 + } + }, + "text": {}, + "binary": {} + }, + "RowCtor": null, + "rowAsArray": false, + "_prebuiltEmptyResultObject": null + }, + { + "command": "COMMIT", + "rowCount": null, + "oid": null, + "rows": [], + "fields": [], + "_types": { + "_types": { + "arrayParser": {}, + "builtins": { + "BOOL": 16, + "BYTEA": 17, + "CHAR": 18, + "INT8": 20, + "INT2": 21, + "INT4": 23, + "REGPROC": 24, + "TEXT": 25, + "OID": 26, + "TID": 27, + "XID": 28, + "CID": 29, + "JSON": 114, + "XML": 142, + "PG_NODE_TREE": 194, + "SMGR": 210, + "PATH": 602, + "POLYGON": 604, + "CIDR": 650, + "FLOAT4": 700, + "FLOAT8": 701, + "ABSTIME": 702, + "RELTIME": 703, + "TINTERVAL": 704, + "CIRCLE": 718, + "MACADDR8": 774, + "MONEY": 790, + "MACADDR": 829, + "INET": 869, + "ACLITEM": 1033, + "BPCHAR": 1042, + "VARCHAR": 1043, + "DATE": 1082, + "TIME": 1083, + "TIMESTAMP": 1114, + "TIMESTAMPTZ": 1184, + "INTERVAL": 1186, + "TIMETZ": 1266, + "BIT": 1560, + "VARBIT": 1562, + "NUMERIC": 1700, + "REFCURSOR": 1790, + "REGPROCEDURE": 2202, + "REGOPER": 2203, + "REGOPERATOR": 2204, + "REGCLASS": 2205, + "REGTYPE": 2206, + "UUID": 2950, + "TXID_SNAPSHOT": 2970, + "PG_LSN": 3220, + "PG_NDISTINCT": 3361, + "PG_DEPENDENCIES": 3402, + "TSVECTOR": 3614, + "TSQUERY": 3615, + "GTSVECTOR": 3642, + "REGCONFIG": 3734, + "REGDICTIONARY": 3769, + "JSONB": 3802, + "REGNAMESPACE": 4089, + "REGROLE": 4096 + } + }, + "text": {}, + "binary": {} + }, + "RowCtor": null, + "rowAsArray": false, + "_prebuiltEmptyResultObject": null + } + ], +}; \ No newline at end of file diff --git a/test/lib/postgres-creator.js b/test/lib/postgres-creator.js index 76d394e..ecc6025 100644 --- a/test/lib/postgres-creator.js +++ b/test/lib/postgres-creator.js @@ -9,6 +9,7 @@ const PostgresCreator = require('../../lib/postgres-creator'); const DBErrors = require('../../lib/errors'); const { nop, itChecksImplementation } = require('../helpers'); const { StubLogger } = require('@squeep/test-helper'); +const { multiResultResponse } = require('../data/postgres'); describe('Postgres Creator', function () { let db, options, stubLogger; @@ -159,7 +160,7 @@ describe('Postgres Creator', function () { describe('_initTables', function () { beforeEach(function () { - sinon.stub(db.db, 'multiResult').resolves(); + sinon.stub(db.db, 'multiResult').resolves(multiResultResponse); sinon.stub(db, '_currentSchema'); sinon.stub(db, '_tableExists'); sinon.stub(fs, 'readdirSync').returns([]);