Remove support for alternative plugin databases
This commit is contained in:
@@ -76,27 +76,6 @@ describe('SingleConnectionDatabaseManager', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('allows plugins to get alternative databases', async () => {
|
||||
const pluginId = 'test1';
|
||||
const pluginManager = manager.forPlugin(pluginId);
|
||||
await pluginManager.getClient();
|
||||
|
||||
const secondaryDatabase = 'extra';
|
||||
await pluginManager.getClient(secondaryDatabase);
|
||||
|
||||
expect(mocked(createDatabaseClient).mock.calls).toHaveLength(2);
|
||||
const mockCalls = mocked(createDatabaseClient).mock.calls.splice(-2);
|
||||
|
||||
const mainCallArgs = mockCalls[0];
|
||||
const secondaryCallArgs = mockCalls[1];
|
||||
expect(secondaryCallArgs[1].connection.database).toEqual(
|
||||
`backstage_plugin_${pluginId}_${secondaryDatabase}`,
|
||||
);
|
||||
expect(mainCallArgs[1].connection.database).not.toEqual(
|
||||
secondaryCallArgs[1].connection.database,
|
||||
);
|
||||
});
|
||||
|
||||
it('provides different plugins different databases', async () => {
|
||||
const plugin1Id = 'test1';
|
||||
const plugin2Id = 'test2';
|
||||
|
||||
@@ -61,17 +61,16 @@ export class SingleConnectionDatabaseManager {
|
||||
const _this = this;
|
||||
|
||||
return {
|
||||
getClient(database?: string): Promise<Knex> {
|
||||
return _this.getDatabase(pluginId, database);
|
||||
getClient(): Promise<Knex> {
|
||||
return _this.getDatabase(pluginId);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async getDatabase(pluginId: string, suffix?: string): Promise<Knex> {
|
||||
private async getDatabase(pluginId: string): Promise<Knex> {
|
||||
const config = this.getDatabaseConfig();
|
||||
const overrides = SingleConnectionDatabaseManager.getDatabaseOverrides(
|
||||
pluginId,
|
||||
suffix,
|
||||
);
|
||||
const overrideConfig = overrides.connection as Knex.ConnectionConfig;
|
||||
await this.ensureDatabase(overrideConfig.database);
|
||||
@@ -79,14 +78,10 @@ export class SingleConnectionDatabaseManager {
|
||||
return createDatabaseClient(config, overrides);
|
||||
}
|
||||
|
||||
private static getDatabaseOverrides(
|
||||
pluginId: string,
|
||||
suffix?: string,
|
||||
): Knex.Config {
|
||||
const dbSuffix = suffix ? `_${suffix}` : '';
|
||||
private static getDatabaseOverrides(pluginId: string): Knex.Config {
|
||||
return {
|
||||
connection: {
|
||||
database: `backstage_plugin_${pluginId}${dbSuffix}`,
|
||||
database: `backstage_plugin_${pluginId}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,11 +25,6 @@ export interface PluginDatabaseManager {
|
||||
*
|
||||
* The purpose of this method is to allow plugins to get isolated data
|
||||
* stores so that plugins are discouraged from database integration.
|
||||
*
|
||||
* @param database This parameter can be omitted to get the default plugin
|
||||
* database, or provide an identifier that will be used to identify a
|
||||
* separate database from the default to connect to. This can be used for
|
||||
* application-level sharding.
|
||||
*/
|
||||
getClient(database?: string): Promise<knex>;
|
||||
getClient(): Promise<knex>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user