From 9f2a8dc42311e826a57451d957b465f956d5cf93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Sun, 16 Jan 2022 14:54:05 +0100 Subject: [PATCH] add migration to remove the old tables, and some cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/khaki-adults-own.md | 56 +++++++++++++++++++ plugins/catalog-backend/api-report.md | 9 +-- .../20220116144621_remove_legacy.js | 28 ++++++++++ .../src/service/CatalogBuilder.ts | 2 +- .../src/service/createRouter.ts | 10 ++++ .../src/service/standaloneServer.ts | 2 +- 6 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 .changeset/khaki-adults-own.md create mode 100644 plugins/catalog-backend/migrations/20220116144621_remove_legacy.js diff --git a/.changeset/khaki-adults-own.md b/.changeset/khaki-adults-own.md new file mode 100644 index 0000000000..9b7bebbff0 --- /dev/null +++ b/.changeset/khaki-adults-own.md @@ -0,0 +1,56 @@ +--- +'@backstage/plugin-catalog-backend': minor +--- + +**BREAKING CHANGE**: Removed all remnants of the old catalog engine +implementation. + +The old implementation has been deprecated for over half a year. To ensure that +you are not using the old implementation, check that your +`packages/backend/src/plugins/catalog.ts` creates the catalog builder using +`CatalogBuilder.create`. If you instead call `new CatalogBuilder`, you are on +the old implementation and will experience breakage if you upgrade to this +version. If you are still on the old version, see [the relevant change log +entry](https://github.com/backstage/backstage/blob/master/plugins/catalog-backend/CHANGELOG.md#patch-changes-27) +for migration instructions. + +The following classes and interfaces have been removed: + +- The `CatalogBuilder` constructor (see above; use `CatalogBuilder.create` + instead) +- `AddLocationResult` +- `CommonDatabase` +- `CreateDatabaseOptions` +- `createNextRouter` (use `createRouter` instead - or preferably, use the + `router` field returned for you by `catalogBuilder.build()`) +- `Database` +- `DatabaseEntitiesCatalog` (use `EntitiesCatalog` instead) +- `DatabaseLocationsCatalog` (use `LocationService` instead) +- `DatabaseLocationUpdateLogEvent` +- `DatabaseLocationUpdateLogStatus` +- `DatabaseManager` +- `DbEntitiesRequest` +- `DbEntitiesResponse` +- `DbEntityRequest` +- `DbEntityResponse` +- `DbLocationsRow` +- `DbLocationsRowWithStatus` +- `DbPageInfo` +- `HigherOrderOperation` +- `HigherOrderOperations` +- `LocationReader` +- `LocationReaders` +- `LocationResponse` +- `LocationsCatalog` +- `LocationUpdateLogEvent` +- `LocationUpdateStatus` +- `NextCatalogBuilder` (use `CatalogBuilder.create` instead) +- `NextRouterOptions` (use `RouterOptions` instead) +- `ReadLocationEntity` +- `ReadLocationError` +- `ReadLocationResult` +- `Transaction` + +The `RouterOptions` interface has been un-deprecated, and has instead found use +for passing into `createRouter`. Its shape has been significantly changed to +accommodate the new router. diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 575a541de9..fd253695a2 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -238,7 +238,6 @@ export class BuiltinKindsEntityProcessor implements CatalogProcessor { // @public export class CatalogBuilder { - constructor(env: CatalogEnvironment); addEntityPolicy(...policies: EntityPolicy[]): CatalogBuilder; addEntityProvider(...providers: EntityProvider[]): CatalogBuilder; addPermissionRules( @@ -463,9 +462,7 @@ export function createRandomRefreshInterval(options: { maxSeconds: number; }): RefreshIntervalFunction; -// Warning: (ae-missing-release-tag) "createRouter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) +// @public export function createRouter(options: RouterOptions): Promise; // Warning: (ae-missing-release-tag) "DefaultCatalogCollator" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -1080,9 +1077,7 @@ declare namespace results { } export { results }; -// Warning: (ae-missing-release-tag) "RouterOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) +// @public export interface RouterOptions { // (undocumented) config: Config; diff --git a/plugins/catalog-backend/migrations/20220116144621_remove_legacy.js b/plugins/catalog-backend/migrations/20220116144621_remove_legacy.js new file mode 100644 index 0000000000..b7992ec261 --- /dev/null +++ b/plugins/catalog-backend/migrations/20220116144621_remove_legacy.js @@ -0,0 +1,28 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// @ts-check + +/** + * @param {import('knex').Knex} knex + */ +exports.up = async function up(knex) { + await knex.schema.dropTable('entities_relations'); + await knex.schema.dropTable('entities_search'); + await knex.schema.dropTable('entities'); +}; + +exports.down = async function down() {}; diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index 8a2e1884d6..29f1ebae8f 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -154,7 +154,7 @@ export class CatalogBuilder { return new CatalogBuilder(env); } - constructor(env: CatalogEnvironment) { + private constructor(env: CatalogEnvironment) { this.env = env; this.entityPolicies = []; this.entityPoliciesReplace = false; diff --git a/plugins/catalog-backend/src/service/createRouter.ts b/plugins/catalog-backend/src/service/createRouter.ts index 2cf602f897..fc60577141 100644 --- a/plugins/catalog-backend/src/service/createRouter.ts +++ b/plugins/catalog-backend/src/service/createRouter.ts @@ -37,6 +37,11 @@ import { import { disallowReadonlyMode, validateRequestBody } from './util'; import { RefreshOptions, LocationService, RefreshService } from './types'; +/** + * Options used by {@link createRouter}. + * + * @public + */ export interface RouterOptions { entitiesCatalog?: EntitiesCatalog; locationAnalyzer?: LocationAnalyzer; @@ -47,6 +52,11 @@ export interface RouterOptions { permissionIntegrationRouter?: express.Router; } +/** + * Creates a catalog router. + * + * @public + */ export async function createRouter( options: RouterOptions, ): Promise { diff --git a/plugins/catalog-backend/src/service/standaloneServer.ts b/plugins/catalog-backend/src/service/standaloneServer.ts index 81deb99b74..ba5604a561 100644 --- a/plugins/catalog-backend/src/service/standaloneServer.ts +++ b/plugins/catalog-backend/src/service/standaloneServer.ts @@ -62,7 +62,7 @@ export async function startStandaloneServer( logger.debug('Creating application...'); await applyDatabaseMigrations(await database.getClient()); - const builder = new CatalogBuilder({ + const builder = CatalogBuilder.create({ logger, database, config,