Set CRDB options to avoid inconsistencies between vendors (#11193)

* Set correct CRDB options

* Add missing SETs to pool config for e2e

* How about now

* Better solution for the same problem
This commit is contained in:
Rijk van Zanten
2022-01-20 20:18:22 -05:00
committed by GitHub
parent 3cbe86d3f1
commit 88c87f3920
4 changed files with 34 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import { knex, Knex } from 'knex';
import path from 'path';
import { promisify } from 'util';
export type Credentials = {
filename?: string;
@@ -55,12 +56,24 @@ export default function createDBConnection(
extension: 'js',
directory: path.resolve(__dirname, '../../database/seeds/'),
},
pool: {},
};
if (client === 'sqlite3') {
knexConfig.useNullAsDefault = true;
}
if (client === 'cockroachdb') {
knexConfig.pool!.afterCreate = async (conn: any, callback: any) => {
const run = promisify(conn.query.bind(conn));
await run('SET serial_normalization = "sql_sequence"');
await run('SET default_int_size = 4');
callback(null, conn);
};
}
const db = knex(knexConfig);
return db;
}