diff --git a/lib/dialects/postgres/schema/pg-columncompiler.js b/lib/dialects/postgres/schema/pg-columncompiler.js index a7cd3e32b..443f734b5 100644 --- a/lib/dialects/postgres/schema/pg-columncompiler.js +++ b/lib/dialects/postgres/schema/pg-columncompiler.js @@ -145,6 +145,7 @@ function jsonColumn(client, jsonb) { if ( !client.version || client.config.client === 'cockroachdb' || + client.config.jsonbSupport === true || parseFloat(client.version) >= 9.2 ) { return jsonb ? 'jsonb' : 'json'; diff --git a/test/unit/schema-builder/postgres.js b/test/unit/schema-builder/postgres.js index a77f68c7a..1e91a8101 100644 --- a/test/unit/schema-builder/postgres.js +++ b/test/unit/schema-builder/postgres.js @@ -93,6 +93,41 @@ describe('PostgreSQL Config', function () { ); }); }); + + describe('check custom pg client', function () { + it('jsonb as text', function () { + knexInstance = knex({ + ...config, + version: 'custom-pg', + jsonbSupport: false, + }); + tableSql = knexInstance.schema + .table('public', function (t) { + t.jsonb('test_name'); + }) + .toSQL(); + equal(1, tableSql.length); + expect(tableSql[0].sql).to.equal( + 'alter table "public" add column "test_name" text' + ); + }); + it('jsonb', function () { + knexInstance = knex({ + ...config, + version: 'custom-pg', + jsonbSupport: true, + }); + tableSql = knexInstance.schema + .table('public', function (t) { + t.jsonb('test_name'); + }) + .toSQL(); + equal(1, tableSql.length); + expect(tableSql[0].sql).to.equal( + 'alter table "public" add column "test_name" jsonb' + ); + }); + }); }); }); diff --git a/types/index.d.ts b/types/index.d.ts index c352a6593..17de2e555 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2699,6 +2699,7 @@ export declare namespace Knex { debug?: boolean; client?: string | typeof Client; dialect?: string; + jsonbSupport?: boolean; version?: string; connection?: string | StaticConnectionConfig | ConnectionConfigProvider; pool?: PoolConfig;