backend-{common,tasks}: stop depending on full DatabaseManager type

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-02-08 12:14:50 +01:00
parent c641dae287
commit 67072166a9
6 changed files with 32 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Added a new `LegacyRootDatabaseService` interface that can be used to avoid direct dependencies on the `DatabaseManager`.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-tasks': patch
---
The `TaskScheduler.fromConfig` method now accepts the `LegacyRootDatabaseService` interface rather than the full `DatabaseManager` implementation.
+6 -1
View File
@@ -249,7 +249,7 @@ export function createStatusCheckRouter(options: {
}): Promise<express.Router>;
// @public
export class DatabaseManager {
export class DatabaseManager implements LegacyRootDatabaseService {
forPlugin(
pluginId: string,
deps?: {
@@ -555,6 +555,11 @@ export const legacyPlugin: (
}>,
) => BackendFeature;
// @public
export type LegacyRootDatabaseService = {
forPlugin(pluginId: string): PluginDatabaseManager;
};
// @public
export function loadBackendConfig(options: {
logger: LoggerService;
@@ -30,6 +30,7 @@ import {
import { PluginDatabaseManager } from './types';
import path from 'path';
import {
DatabaseService,
LifecycleService,
LoggerService,
PluginMetadataService,
@@ -53,6 +54,14 @@ export type DatabaseManagerOptions = {
logger?: LoggerService;
};
/**
* An interface that represents the legacy global DatabaseManager implementation.
* @public
*/
export type LegacyRootDatabaseService = {
forPlugin(pluginId: string): DatabaseService;
};
/**
* Manages database connections for Backstage backend plugins.
*
@@ -65,7 +74,7 @@ export type DatabaseManagerOptions = {
* set `prefix` which is used to prefix generated database names if config is
* not provided.
*/
export class DatabaseManager {
export class DatabaseManager implements LegacyRootDatabaseService {
/**
* Creates a {@link DatabaseManager} from `backend.database` config.
*
+3 -3
View File
@@ -4,10 +4,10 @@
```ts
import { Config } from '@backstage/config';
import { DatabaseManager } from '@backstage/backend-common';
import { Duration } from 'luxon';
import { HumanDuration as HumanDuration_2 } from '@backstage/types';
import { JsonObject } from '@backstage/types';
import { LegacyRootDatabaseService } from '@backstage/backend-common';
import { Logger } from 'winston';
import { PluginDatabaseManager } from '@backstage/backend-common';
@@ -83,7 +83,7 @@ export interface TaskScheduleDefinitionConfig {
// @public
export class TaskScheduler {
constructor(databaseManager: DatabaseManager, logger: Logger);
constructor(databaseManager: LegacyRootDatabaseService, logger: Logger);
forPlugin(pluginId: string): PluginTaskScheduler;
// (undocumented)
static forPlugin(opts: {
@@ -95,7 +95,7 @@ export class TaskScheduler {
static fromConfig(
config: Config,
options?: {
databaseManager?: DatabaseManager;
databaseManager?: LegacyRootDatabaseService;
logger?: Logger;
},
): TaskScheduler;
@@ -17,6 +17,7 @@
import {
DatabaseManager,
getRootLogger,
LegacyRootDatabaseService,
PluginDatabaseManager,
} from '@backstage/backend-common';
import { Config } from '@backstage/config';
@@ -37,7 +38,7 @@ export class TaskScheduler {
static fromConfig(
config: Config,
options?: {
databaseManager?: DatabaseManager;
databaseManager?: LegacyRootDatabaseService;
logger?: Logger;
},
): TaskScheduler {
@@ -50,7 +51,7 @@ export class TaskScheduler {
}
constructor(
private readonly databaseManager: DatabaseManager,
private readonly databaseManager: LegacyRootDatabaseService,
private readonly logger: Logger,
) {}