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

Allow passing version of connected db in configuration file #1993

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/dialects/postgres/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ import SchemaCompiler from './schema/compiler';
import {makeEscape} from '../../query/string'

function Client_PG(config) {
Client.apply(this, arguments)
Client.apply(this, arguments);
if (config.returning) {
this.defaultReturning = config.returning;
}

if (config.searchPath) {
this.searchPath = config.searchPath;
}

if (config.version) {
this.version = config.version;
}
}
inherits(Client_PG, Client)
inherits(Client_PG, Client);

assign(Client_PG.prototype, {

Expand Down
74 changes: 73 additions & 1 deletion test/unit/schema/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,82 @@
var tableSql;

var PG_Client = require('../../../lib/dialects/postgres');
var client = new PG_Client({})
var client = new PG_Client({});
var knex = require('../../../knex');

var equal = require('assert').equal;

describe('PostgreSQL Config', function() {
var knexInstance;
var version;
var config = {
client: 'pg',
connection: {
user: 'postgres',
password: '',
host: '127.0.0.1',
database: 'knex_test'
}
};
describe('check version', function() {
describe('check version < 9.2', function() {
beforeEach(function () {
version = '7.2';
config.version = version;
knexInstance = knex(config);
});

it('client.version', function(){
expect(knexInstance.client.version).to.equal(version);
});

it('json', function() {
tableSql = knexInstance.schema.table('public', function(t) {
t.json('test_name');
}).toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal('alter table "public" add column "test_name" text');
});

it('jsonb', function() {
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');
});
});

describe('check version >= 9.2', function() {
beforeEach(function() {
version = '9.5';
config.version = version;
knexInstance = knex(config);
});

it('client.version', function(){
expect(knexInstance.client.version).to.equal(version);
});

it('json', function() {
tableSql = knexInstance.schema.table('public', function(t) {
t.json('test_name');
}).toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal('alter table "public" add column "test_name" json');
});

it('jsonb', function() {
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');
});
});
});
});

describe("PostgreSQL SchemaBuilder", function() {

it("fixes memoization regression", function() {
Expand Down