Skip to content

Commit

Permalink
Upgrade Knex to v3.1.0
Browse files Browse the repository at this point in the history
The migration guide can be found here
https://github.com/knex/knex/blob/176151d8048b2a7feeb89a3d649a5580786d4f4e/UPGRADING.md

In section "Upgrading to version 0.95.0+", the only
change that affects us is the import style change.

Other sections, regarding upgrades to higher major
versions of Knex, don't have anything that affects us.
  • Loading branch information
Pl217 committed Aug 26, 2024
1 parent 9a49a64 commit 7542b71
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"bunyan": "^1.8.15",
"class-validator": "^0.14.0",
"graphql": "^15.7.2",
"knex": "0.21.1",
"knex": "3.1.0",
"pg": "^8.11.3",
"pm2": "^5.3.0",
"reflect-metadata": "^0.1.13",
Expand Down
8 changes: 4 additions & 4 deletions src/data-providers/postgres/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Knex from 'knex';
import { knex } from 'knex';
import { CONFIG } from '../../../config';

/**
* Initialize a new Postgres provider
*/
export async function createDbConnection() {
const knex = Knex({
const knexInstance = knex({
client: 'pg',
connection: CONFIG.db.connection,
pool: {
Expand All @@ -18,9 +18,9 @@ export async function createDbConnection() {

// Verify the connection before proceeding
try {
await knex.raw('SELECT now()');
await knexInstance.raw('SELECT now()');

return knex;
return knexInstance;
} catch {
throw new Error(
'Unable to connect to Postgres via Knex. Ensure a valid connection.'
Expand Down
5 changes: 2 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import * as Hapi from '@hapi/hapi';
import v4Models from '@unocha/hpc-api-core/src/db';
import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';
import {
ApolloServer,
ApolloServerPluginStopHapiServer,
} from 'apollo-server-hapi';
import { type Knex } from 'knex';
import { join } from 'node:path';
import 'reflect-metadata';
import { buildSchema } from 'type-graphql';
import { Container } from 'typedi';
import Knex = require('knex');

import v4Models from '@unocha/hpc-api-core/src/db';
import { CONFIG } from '../config';
import { getTokenFromRequest } from './common-libs/auth';
import { initializeLogging } from './common-libs/logging';
Expand Down
2 changes: 1 addition & 1 deletion tests/testContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import v4Models, { type Database } from '@unocha/hpc-api-core/src/db';
import { type ApolloServer } from 'apollo-server-hapi';
import type Knex from 'knex';
import type { Knex } from 'knex';
import { createDbConnection } from './utils/connection';
import createApolloTestServer from './utils/server';

Expand Down
8 changes: 4 additions & 4 deletions tests/utils/connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as t from 'io-ts';
import Knex from 'knex';
import { knex } from 'knex';

const CONFIG = t.type({
host: t.string,
Expand All @@ -12,7 +12,7 @@ const CONFIG = t.type({
* Initialize a new Postgres provider
*/
export async function createDbConnection(connection: t.TypeOf<typeof CONFIG>) {
const knex = Knex({
const knexInstance = knex({
client: 'pg',
connection,
pool: { min: 0, max: 10, idleTimeoutMillis: 500 },
Expand All @@ -21,9 +21,9 @@ export async function createDbConnection(connection: t.TypeOf<typeof CONFIG>) {

// Verify the connection before proceeding
try {
await knex.raw('SELECT now()');
await knexInstance.raw('SELECT now()');

return knex;
return knexInstance;
} catch (error) {
console.log(error);
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ApolloServer,
ApolloServerPluginStopHapiServer,
} from 'apollo-server-hapi';
import type Knex from 'knex';
import type { Knex } from 'knex';
import PlatformPath from 'node:path';
import 'reflect-metadata';
import { buildSchema } from 'type-graphql';
Expand Down
51 changes: 49 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.1.0.tgz#1f943e5a357fac10b4e0f5aaef3b14cdc1af6ec7"
integrity sha512-6S062WDQUXi6hOfkO/sBPVwE5ASXY4G2+b4atvhJfSsuUUhIaUKlkjLe9692Ipyt5/a+IPF5aVTu3V5gvXq5cg==

[email protected]:
version "2.0.19"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798"
integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==

colorette@^2.0.20:
version "2.0.20"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.20.tgz#9eb793e6833067f7235902fcd3b09917a000a95a"
Expand All @@ -2383,6 +2388,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
integrity sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==

commander@^10.0.0:
version "10.0.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06"
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==

commander@^2.20.3:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
Expand Down Expand Up @@ -3248,6 +3258,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.2.5.tgz#67a0fe471cacb9c687d817cab6450b96dde8313b"
integrity sha512-9jb7AW5p3in+IiJWhQiZmmwkpLaR/ccTWdWQCtZM66HJcHHLegowh4q4tSD7gouUyeNvFWRavfK9GXosQHDpFA==

[email protected]:
version "2.3.0"
resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.3.0.tgz#71e5593284807e03e2427449d4f6712a268666f4"
integrity sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==

git-node-fs@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/git-node-fs/-/git-node-fs-1.0.0.tgz#49b215e242ebe43aa4c7561bbba499521752080f"
Expand Down Expand Up @@ -3580,7 +3595,7 @@ ini@^1.3.4, ini@^1.3.5:
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

interpret@^2.0.0:
interpret@^2.0.0, interpret@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9"
integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==
Expand Down Expand Up @@ -4367,6 +4382,26 @@ [email protected]:
uuid "^7.0.3"
v8flags "^3.1.3"

[email protected]:
version "3.1.0"
resolved "https://registry.yarnpkg.com/knex/-/knex-3.1.0.tgz#b6ddd5b5ad26a6315234a5b09ec38dc4a370bd8c"
integrity sha512-GLoII6hR0c4ti243gMs5/1Rb3B+AjwMOfjYm97pu0FOQa7JH56hgBxYf5WK2525ceSbBY1cjeZ9yk99GPMB6Kw==
dependencies:
colorette "2.0.19"
commander "^10.0.0"
debug "4.3.4"
escalade "^3.1.1"
esm "^3.2.25"
get-package-type "^0.1.0"
getopts "2.3.0"
interpret "^2.2.0"
lodash "^4.17.21"
pg-connection-string "2.6.2"
rechoir "^0.8.0"
resolve-from "^5.0.0"
tarn "^3.0.2"
tildify "2.0.0"

lazy@~1.0.11:
version "1.0.11"
resolved "https://registry.yarnpkg.com/lazy/-/lazy-1.0.11.tgz#daa068206282542c088288e975c297c1ae77b690"
Expand Down Expand Up @@ -5070,7 +5105,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.2.0.tgz#caab4d38a9de4fdc29c9317acceed752897de41c"
integrity sha512-xB/+wxcpFipUZOQcSzcgkjcNOosGhEoPSjz06jC89lv1dj7mc9bZv6wLVy8M2fVjP0a/xN0N988YDq1L0FhK3A==

pg-connection-string@^2.6.2:
pg-connection-string@2.6.2, pg-connection-string@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.6.2.tgz#713d82053de4e2bd166fab70cd4f26ad36aab475"
integrity sha512-ch6OwaeaPYcova4kKZ15sbJ2hKb/VP48ZD2gE7i1J+L4MspCtBMAx8nMgz7bksc7IojCIIWuEhHibSMFH8m8oA==
Expand Down Expand Up @@ -5485,6 +5520,13 @@ rechoir@^0.6.2:
dependencies:
resolve "^1.1.6"

rechoir@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22"
integrity sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==
dependencies:
resolve "^1.20.0"

reflect-metadata@^0.1.13:
version "0.1.13"
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"
Expand Down Expand Up @@ -6085,6 +6127,11 @@ tarn@^3.0.0:
resolved "https://registry.yarnpkg.com/tarn/-/tarn-3.0.1.tgz#ebac2c6dbc6977d34d4526e0a7814200386a8aec"
integrity sha512-6usSlV9KyHsspvwu2duKH+FMUhqJnAh6J5J/4MITl8s94iSUQTLkJggdiewKv4RyARQccnigV48Z+khiuVZDJw==

tarn@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/tarn/-/tarn-3.0.2.tgz#73b6140fbb881b71559c4f8bfde3d9a4b3d27693"
integrity sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ==

test-exclude@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"
Expand Down

0 comments on commit 7542b71

Please sign in to comment.