Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit jsonb support for custom pg clients #5201

1 change: 1 addition & 0 deletions lib/dialects/postgres/schema/pg-columncompiler.js
Expand Up @@ -139,6 +139,7 @@ function jsonColumn(client, jsonb) {
if (
!client.version ||
client.config.client === 'cockroachdb' ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was cockroachdb removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brought it back , I removed it initially just to get a sense of the tests in order to eventually replicate them for pg-mem

client.config.jsonbSupport === true ||
parseFloat(client.version) >= 9.2
) {
return jsonb ? 'jsonb' : 'json';
Expand Down
36 changes: 35 additions & 1 deletion test/unit/schema-builder/postgres.js
Expand Up @@ -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'
);
});
});
});
});

Expand Down Expand Up @@ -446,7 +481,6 @@ describe('PostgreSQL SchemaBuilder', function () {
);
});


it('refresh view concurrently', function () {
tableSql = client
.schemaBuilder()
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Expand Up @@ -2310,6 +2310,7 @@ export declare namespace Knex {
debug?: boolean;
client?: string | typeof Client;
dialect?: string;
jsonbSupport?: boolean;
version?: string;
connection?: string | StaticConnectionConfig | ConnectionConfigProvider;
pool?: PoolConfig;
Expand Down