Skip to content

Commit

Permalink
Merge pull request backstage#4827 from backstage/dependabot/npm_and_y…
Browse files Browse the repository at this point in the history
…arn/knex-0.95.1

chore(deps): bump knex from 0.21.18 to 0.95.1
  • Loading branch information
freben authored Mar 8, 2021
2 parents c598de8 + 7616988 commit 8e15b19
Show file tree
Hide file tree
Showing 41 changed files with 160 additions and 258 deletions.
18 changes: 18 additions & 0 deletions .changeset/nasty-garlics-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@backstage/backend-common': patch
---

Bump to the latest version of the Knex library.

You will most likely want to bump your own `packages/backend/package.json` as well:

```diff
- "knex": "^0.21.18",
+ "knex": "^0.95.1",
```

Note that the recent versions of the Knex library have some changes that may affect your internal plugins' database migration files. Importantly, they now support `ALTER TABLE` on SQLite, and no longer accidentally remove indices when making some modifications. It now also exports the `Knex` typescript type as a named export.

```ts
import { Knex } from 'knex';
```
8 changes: 8 additions & 0 deletions .changeset/old-laws-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@backstage/plugin-auth-backend': patch
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-scaffolder-backend': patch
'@backstage/plugin-techdocs-backend': patch
---

Bump to the latest version of the Knex library.
2 changes: 1 addition & 1 deletion packages/backend-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"git-url-parse": "^11.4.4",
"helmet": "^4.0.0",
"isomorphic-git": "^1.8.0",
"knex": "^0.21.6",
"knex": "^0.95.1",
"lodash": "^4.17.15",
"logform": "^2.1.1",
"minimatch": "^3.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-common/src/database/SingleConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import Knex from 'knex';
import { Knex } from 'knex';
import { Config } from '@backstage/config';
import { createDatabaseClient, ensureDatabaseExists } from './connection';
import { PluginDatabaseManager } from './types';
Expand Down
6 changes: 3 additions & 3 deletions packages/backend-common/src/database/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import knex from 'knex';
import knexFactory, { Knex } from 'knex';
import { Config } from '@backstage/config';
import { mergeDatabaseConfig } from './config';
import { createPgDatabaseClient, ensurePgDatabaseExists } from './postgres';
Expand All @@ -30,7 +30,7 @@ type DatabaseClient = 'pg' | 'sqlite3' | string;
*/
export function createDatabaseClient(
dbConfig: Config,
overrides?: Partial<knex.Config>,
overrides?: Partial<Knex.Config>,
) {
const client: DatabaseClient = dbConfig.getString('client');

Expand All @@ -40,7 +40,7 @@ export function createDatabaseClient(
return createSqliteDatabaseClient(dbConfig);
}

return knex(mergeDatabaseConfig(dbConfig.get(), overrides));
return knexFactory(mergeDatabaseConfig(dbConfig.get(), overrides));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/backend-common/src/database/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import knex, { PgConnectionConfig } from 'knex';
import knexFactory, { Knex } from 'knex';
import { Config } from '@backstage/config';
import { mergeDatabaseConfig } from './config';

Expand All @@ -26,10 +26,10 @@ import { mergeDatabaseConfig } from './config';
*/
export function createPgDatabaseClient(
dbConfig: Config,
overrides?: knex.Config,
overrides?: Knex.Config,
) {
const knexConfig = buildPgDatabaseConfig(dbConfig, overrides);
const database = knex(knexConfig);
const database = knexFactory(knexConfig);
return database;
}

Expand All @@ -41,7 +41,7 @@ export function createPgDatabaseClient(
*/
export function buildPgDatabaseConfig(
dbConfig: Config,
overrides?: knex.Config,
overrides?: Knex.Config,
) {
return mergeDatabaseConfig(
dbConfig.get(),
Expand All @@ -62,7 +62,7 @@ export function buildPgDatabaseConfig(
export function getPgConnectionConfig(
dbConfig: Config,
parseConnectionString?: boolean,
): PgConnectionConfig | string {
): Knex.PgConnectionConfig | string {
const connection = dbConfig.get('connection') as any;
const isConnectionString =
typeof connection === 'string' || connection instanceof String;
Expand Down
8 changes: 4 additions & 4 deletions packages/backend-common/src/database/sqlite3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import knex from 'knex';
import knexFactory, { Knex } from 'knex';
import { Config } from '@backstage/config';
import { mergeDatabaseConfig } from './config';

Expand All @@ -26,10 +26,10 @@ import { mergeDatabaseConfig } from './config';
*/
export function createSqliteDatabaseClient(
dbConfig: Config,
overrides?: knex.Config,
overrides?: Knex.Config,
) {
const knexConfig = buildSqliteDatabaseConfig(dbConfig, overrides);
const database = knex(knexConfig);
const database = knexFactory(knexConfig);

database.client.pool.on('createSuccess', (_eventId: any, resource: any) => {
resource.run('PRAGMA foreign_keys = ON', () => {});
Expand All @@ -46,7 +46,7 @@ export function createSqliteDatabaseClient(
*/
export function buildSqliteDatabaseConfig(
dbConfig: Config,
overrides?: knex.Config,
overrides?: Knex.Config,
) {
return mergeDatabaseConfig(
dbConfig.get(),
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-common/src/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import knex from 'knex';
import { Knex } from 'knex';

/**
* The PluginDatabaseManager manages access to databases that Plugins get.
Expand All @@ -26,5 +26,5 @@ export interface PluginDatabaseManager {
* The purpose of this method is to allow plugins to get isolated data
* stores so that plugins are discouraged from database integration.
*/
getClient(): Promise<knex>;
getClient(): Promise<Knex>;
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"example-app": "^0.2.18",
"express": "^4.17.1",
"express-promise-router": "^3.0.3",
"knex": "^0.21.6",
"knex": "^0.95.1",
"pg": "^8.3.0",
"pg-connection-string": "^2.3.0",
"sqlite3": "^5.0.0",
Expand Down
4 changes: 2 additions & 2 deletions plugins/auth-backend/migrations/20200619125845_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
return knex.schema.createTable('signing_keys', table => {
Expand All @@ -39,7 +39,7 @@ exports.up = async function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
return knex.schema.dropTable('auth_keystore');
Expand Down
2 changes: 1 addition & 1 deletion plugins/auth-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"helmet": "^4.0.0",
"jose": "^1.27.1",
"jwt-decode": "^3.1.0",
"knex": "^0.21.6",
"knex": "^0.95.1",
"luxon": "^1.25.0",
"morgan": "^1.10.0",
"node-cache": "^5.1.2",
Expand Down
4 changes: 2 additions & 2 deletions plugins/auth-backend/src/identity/DatabaseKeyStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import Knex from 'knex';
import { resolvePackagePath } from '@backstage/backend-common';
import { AnyJWK, KeyStore, StoredKey } from './types';
import { Knex } from 'knex';
import { DateTime } from 'luxon';
import { AnyJWK, KeyStore, StoredKey } from './types';

const migrationsDir = resolvePackagePath(
'@backstage/plugin-auth-backend',
Expand Down
4 changes: 2 additions & 2 deletions plugins/catalog-backend/migrations/20200511113813_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
return (
Expand Down Expand Up @@ -120,7 +120,7 @@ exports.up = async function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
return knex.schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
return knex.schema.createTable('location_update_log', table => {
Expand All @@ -36,7 +36,7 @@ exports.up = async function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
return knex.schema.dropTableIfExists('location_update_log');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
// Get list sorted by created_at timestamp in descending order
// Grouped by location_id
return knex.schema.raw(`
CREATE VIEW location_update_log_latest AS
SELECT t1.* FROM location_update_log t1
JOIN
JOIN
(
SELECT location_id, MAX(created_at) AS MAXDATE
FROM location_update_log
Expand All @@ -38,7 +38,7 @@ exports.up = async function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
return knex.schema.raw(`DROP VIEW location_update_log_latest;`);
Expand Down
4 changes: 2 additions & 2 deletions plugins/catalog-backend/migrations/20200702153613_entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
// SQLite does not support FK and PK
Expand Down Expand Up @@ -126,7 +126,7 @@ exports.up = async function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
// SQLite does not support FK and PK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// @ts-check

/**
* @param {import('knex').Knex} knex
*/
exports.up = function up(knex) {
return knex.schema.raw(`DROP VIEW location_update_log_latest;`).raw(`
CREATE VIEW location_update_log_latest AS
SELECT t1.* FROM location_update_log t1
JOIN
JOIN
(
SELECT location_id, MAX(created_at) AS MAXDATE
FROM location_update_log
Expand All @@ -30,6 +36,9 @@ exports.up = function up(knex) {
`);
};

/**
* @param {import('knex').Knex} knex
*/
exports.down = function down(knex) {
knex.schema.raw(`DROP VIEW location_update_log_latest;`);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = function up(knex) {
return knex.schema
Expand Down Expand Up @@ -52,7 +52,7 @@ exports.up = function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = function down(knex) {
return knex.schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
// Sqlite does not support alter column.
Expand All @@ -29,7 +29,7 @@ exports.up = async function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
// Sqlite does not support alter column.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
// Adds a single 'bootstrap' location that can be used to trigger work in processors.
Expand All @@ -30,7 +30,7 @@ exports.up = async function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
await knex('locations')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
await knex('entities')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// @ts-check

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
await knex.schema.alterTable('entities', table => {
Expand Down Expand Up @@ -45,7 +45,7 @@ exports.up = async function up(knex) {
};

/**
* @param {import('knex')} knex
* @param {import('knex').Knex} knex
*/
exports.down = async function down(knex) {
await knex.schema.alterTable('entities', table => {
Expand Down
Loading

0 comments on commit 8e15b19

Please sign in to comment.