scrub verbose types from multiResponse logs
authorJustin Wind <justin.wind+git@gmail.com>
Mon, 7 Apr 2025 19:39:30 +0000 (12:39 -0700)
committerJustin Wind <justin.wind+git@gmail.com>
Mon, 7 Apr 2025 19:39:30 +0000 (12:39 -0700)
lib/postgres-creator.js
test/data/postgres.js [new file with mode: 0644]
test/lib/postgres-creator.js

index 88fa66c82cf90ac3a5fba0ded7581dd90f4af817..34e28b1f32a94dc5112f5fb7f133f9f5eab623f7 100644 (file)
@@ -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 (file)
index 0000000..e7f79fa
--- /dev/null
@@ -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
index 76d394e7f300237fe7adc4a87397f4a3b5c188f1..ecc60259ccf5d9ad62389bdee0027579f5f19438 100644 (file)
@@ -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([]);