remove createDatabase and SingleConnectionDatabaseManager that were deprecated years ago :)

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-03-04 12:14:48 +01:00
parent 968ee8d4fc
commit ae9d6fb3df
7 changed files with 9 additions and 170 deletions
+8
View File
@@ -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.
@@ -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
-6
View File
@@ -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(
@@ -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');
});
});
});
@@ -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;
@@ -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.
*
@@ -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';