diff --git a/.changeset/thick-games-dress.md b/.changeset/thick-games-dress.md new file mode 100644 index 0000000000..5ce2decd3f --- /dev/null +++ b/.changeset/thick-games-dress.md @@ -0,0 +1,8 @@ +--- +'@backstage/backend-common': minor +--- + +**BREAKING**: + +- Removed the (since way back) deprecated `createDatabase` export, please use `createDatabaseClient` instead. +- Removed the (since way back) deprecated `SingleConnectionDatabaseManager` export, please use `DatabaseManager` instead. diff --git a/docs/tutorials/configuring-plugin-databases.md b/docs/tutorials/configuring-plugin-databases.md index 5c5f0ffb68..9277bb5028 100644 --- a/docs/tutorials/configuring-plugin-databases.md +++ b/docs/tutorials/configuring-plugin-databases.md @@ -49,29 +49,6 @@ yarn add sqlite3 From an operational perspective, you only need to install drivers for clients that are actively used. -### Database Manager - -Existing Backstage instances should be updated to use `DatabaseManager` from -`@backstage/backend-common` in your `packages/backend/src/index.ts` file, the -`SingleConnectionDatabaseManager` has been deprecated. Import the manager and -update the references as shown below if this is not the case: - -```diff -import { -- SingleConnectionDatabaseManager, -+ DatabaseManager, -} from '@backstage/backend-common'; - -// ... - -function makeCreateEnv(config: Config) { - // ... -- const databaseManager = SingleConnectionDatabaseManager.fromConfig(config); -+ const databaseManager = DatabaseManager.fromConfig(config); - // ... -} -``` - ## Configuration You should set the base database client and connection information in your diff --git a/packages/backend-common/api-report.md b/packages/backend-common/api-report.md index 4ed9bb1514..f9fd164787 100644 --- a/packages/backend-common/api-report.md +++ b/packages/backend-common/api-report.md @@ -170,9 +170,6 @@ export class Contexts { ): Context; } -// @public @deprecated -export const createDatabase: typeof createDatabaseClient; - // @public export function createDatabaseClient( dbConfig: Config, @@ -574,9 +571,6 @@ export type ServiceBuilder = { // @public export function setRootLogger(newLogger: winston.Logger): void; -// @public @deprecated -export const SingleConnectionDatabaseManager: typeof DatabaseManager; - // @public export class SingleHostDiscovery implements PluginEndpointDiscovery { static fromConfig( diff --git a/packages/backend-common/src/database/SingleConnection.test.ts b/packages/backend-common/src/database/SingleConnection.test.ts deleted file mode 100644 index 46d7376d25..0000000000 --- a/packages/backend-common/src/database/SingleConnection.test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2020 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. - */ - -import { ConfigReader } from '@backstage/config'; -import { createDatabaseClient, ensureDatabaseExists } from './connection'; -import { SingleConnectionDatabaseManager } from './SingleConnection'; - -jest.mock('./connection', () => ({ - ...jest.requireActual('./connection'), - createDatabaseClient: jest.fn(), - ensureDatabaseExists: jest.fn(), -})); - -describe('SingleConnectionDatabaseManager', () => { - const defaultConfigOptions = { - backend: { - database: { - client: 'pg', - connection: { - host: 'localhost', - user: 'foo', - password: 'bar', - database: 'foodb', - }, - }, - }, - }; - const defaultConfig = () => new ConfigReader(defaultConfigOptions); - - // This is similar to the ts-jest `mocked` helper. - const mocked = (f: Function) => f as jest.Mock; - - afterEach(() => jest.resetAllMocks()); - - describe('SingleConnectionDatabaseManager.fromConfig', () => { - it('accesses the backend.database key', () => { - const config = defaultConfig(); - const getConfig = jest.spyOn(config, 'getConfig'); - - SingleConnectionDatabaseManager.fromConfig(config); - - expect(getConfig.mock.calls[0][0]).toEqual('backend.database'); - }); - }); - - describe('SingleConnectionDatabaseManager.forPlugin', () => { - const manager = SingleConnectionDatabaseManager.fromConfig(defaultConfig()); - - it('connects to a database scoped to the plugin', async () => { - const pluginId = 'test1'; - await manager.forPlugin(pluginId).getClient(); - - expect(mocked(createDatabaseClient)).toHaveBeenCalledTimes(1); - - const mockCalls = mocked(createDatabaseClient).mock.calls.splice(-1); - const callArgs = mockCalls[0]; - expect(callArgs[1].connection.database).toEqual( - `backstage_plugin_${pluginId}`, - ); - }); - - it('provides different plugins different databases', async () => { - const plugin1Id = 'test1'; - const plugin2Id = 'test2'; - await manager.forPlugin(plugin1Id).getClient(); - await manager.forPlugin(plugin2Id).getClient(); - - expect(mocked(createDatabaseClient)).toHaveBeenCalledTimes(2); - - const mockCalls = mocked(createDatabaseClient).mock.calls; - const plugin1CallArgs = mockCalls[0]; - const plugin2CallArgs = mockCalls[1]; - expect(plugin1CallArgs[1].connection.database).not.toEqual( - plugin2CallArgs[1].connection.database, - ); - }); - - it('ensure plugin database is created', async () => { - await manager.forPlugin('test').getClient(); - const mockCalls = mocked(ensureDatabaseExists).mock.calls.splice(-1); - const [_, database] = mockCalls[0]; - - expect(database).toEqual('backstage_plugin_test'); - }); - }); -}); diff --git a/packages/backend-common/src/database/SingleConnection.ts b/packages/backend-common/src/database/SingleConnection.ts deleted file mode 100644 index a81d60fe83..0000000000 --- a/packages/backend-common/src/database/SingleConnection.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 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. - */ - -import { DatabaseManager } from './DatabaseManager'; - -/** - * Implements a Database Manager which will automatically create new databases - * for plugins when requested. All requested databases are created with the - * credentials provided; if the database already exists no attempt to create - * the database will be made. - * - * @public - * @deprecated Use `DatabaseManager` from `@backend-common` instead. - */ -export const SingleConnectionDatabaseManager = DatabaseManager; diff --git a/packages/backend-common/src/database/connection.ts b/packages/backend-common/src/database/connection.ts index 7fc9df060d..fd0769b8a2 100644 --- a/packages/backend-common/src/database/connection.ts +++ b/packages/backend-common/src/database/connection.ts @@ -57,14 +57,6 @@ export function createDatabaseClient( ); } -/** - * Alias for {@link createDatabaseClient} - * - * @public - * @deprecated Use createDatabaseClient instead - */ -export const createDatabase = createDatabaseClient; - /** * Ensures that the given databases all exist, creating them if they do not. * diff --git a/packages/backend-common/src/database/index.ts b/packages/backend-common/src/database/index.ts index 2a820f7367..0dde1ec239 100644 --- a/packages/backend-common/src/database/index.ts +++ b/packages/backend-common/src/database/index.ts @@ -14,18 +14,13 @@ * limitations under the License. */ -export * from './SingleConnection'; export * from './DatabaseManager'; /* * Undocumented API surface from connection is being reduced for future deprecation. * Avoid exporting additional symbols. */ -export { - createDatabaseClient, - createDatabase, - ensureDatabaseExists, -} from './connection'; +export { createDatabaseClient, ensureDatabaseExists } from './connection'; export type { PluginDatabaseManager } from './types'; export { isDatabaseConflictError } from './util';