Replace PluginDatabaseClientFactory with PluginDatabaseManager
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
getRootLogger,
|
||||
useHotMemoize,
|
||||
notFoundHandler,
|
||||
SingleConnectionManager,
|
||||
SingleConnectionDatabaseManager,
|
||||
SingleHostDiscovery,
|
||||
UrlReaders,
|
||||
} from '@backstage/backend-common';
|
||||
@@ -32,20 +32,12 @@ function makeCreateEnv(config: ConfigReader) {
|
||||
|
||||
root.info(`Created UrlReader ${reader}`);
|
||||
|
||||
const databaseManager = new SingleConnectionManager(
|
||||
config.getConfig('backend.database')
|
||||
);
|
||||
const databaseManager = SingleConnectionDatabaseManager.fromConfig(config);
|
||||
|
||||
return (plugin: string): PluginEnvironment => {
|
||||
const logger = root.child({ type: 'plugin', plugin });
|
||||
const databaseFactory = databaseManager.getDatabaseClientFactory(plugin);
|
||||
return {
|
||||
logger,
|
||||
databaseClientFactory: databaseFactory,
|
||||
config,
|
||||
reader,
|
||||
discovery
|
||||
};
|
||||
const database = databaseManager.forPlugin(plugin);
|
||||
return { logger, database, config, reader, discovery };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,9 @@ import { PluginEnvironment } from '../types';
|
||||
|
||||
export default async function createPlugin({
|
||||
logger,
|
||||
databaseClientFactory,
|
||||
database,
|
||||
config,
|
||||
discovery,
|
||||
}: PluginEnvironment) {
|
||||
return await createRouter({
|
||||
logger,
|
||||
config,
|
||||
database: databaseClientFactory,
|
||||
discovery
|
||||
});
|
||||
return await createRouter({ logger, config, database, discovery });
|
||||
}
|
||||
|
||||
@@ -14,12 +14,11 @@ export default async function createPlugin({
|
||||
logger,
|
||||
config,
|
||||
reader,
|
||||
databaseClientFactory,
|
||||
database,
|
||||
}: PluginEnvironment) {
|
||||
const locationReader = new LocationReaders({ logger, reader, config });
|
||||
|
||||
const db = await DatabaseManager.createDatabase(
|
||||
await databaseClientFactory(),
|
||||
const db = await DatabaseManager.createDatabase(await database.getClient(),
|
||||
{ logger },
|
||||
);
|
||||
const entitiesCatalog = new DatabaseEntitiesCatalog(db);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Logger } from 'winston';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
PluginDatabaseClientFactory,
|
||||
PluginDatabaseManager,
|
||||
PluginEndpointDiscovery,
|
||||
UrlReader
|
||||
UrlReader,
|
||||
} from '@backstage/backend-common';
|
||||
|
||||
export type PluginEnvironment = {
|
||||
logger: Logger;
|
||||
databaseClientFactory: PluginDatabaseClientFactory;
|
||||
database: PluginDatabaseManager;
|
||||
config: Config;
|
||||
reader: UrlReader
|
||||
discovery: PluginEndpointDiscovery;
|
||||
|
||||
Reference in New Issue
Block a user