respect ensureExists when pluginDivisionMode is set to schema.

Signed-off-by: Andrew Duckett <andrew.duckett@gmail.com>
This commit is contained in:
Andrew Duckett
2022-07-21 22:21:53 -05:00
parent 795a804111
commit 770d3f92c4
3 changed files with 39 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
**BREAKING** The config prop `ensureExists` now applies to schema creation when `pluginDivisionMode` is set to `schema`. This means schemas will no longer be automatically created when `ensureExists` is set to `false`. In this case the `pg` database as well as each `schema` must be created out of band.
@@ -612,6 +612,31 @@ describe('DatabaseManager', () => {
);
});
it('ensureExists does not create database or schema when false', async () => {
const testManager = DatabaseManager.fromConfig(
new ConfigReader({
backend: {
database: {
client: 'pg',
pluginDivisionMode: 'schema',
ensureExists: false,
connection: {
host: 'localhost',
user: 'foo',
password: 'bar',
database: 'foodb',
},
},
},
}),
);
const pluginId = 'testdbname';
await testManager.forPlugin(pluginId).getClient();
expect(mocked(ensureDatabaseExists)).toHaveBeenCalledTimes(0);
expect(mocked(ensureSchemaExists)).toHaveBeenCalledTimes(0);
});
it('fetches and merges additional knex config', async () => {
const testManager = DatabaseManager.fromConfig(
new ConfigReader({
@@ -321,13 +321,15 @@ export class DatabaseManager {
let schemaOverrides;
if (this.getPluginDivisionModeConfig() === 'schema') {
try {
schemaOverrides = this.getSchemaOverrides(pluginId);
await ensureSchemaExists(pluginConfig, pluginId);
} catch (error) {
throw new Error(
`Failed to connect to the database to make sure that schema for plugin '${pluginId}' exists, ${error}`,
);
schemaOverrides = this.getSchemaOverrides(pluginId);
if (this.getEnsureExistsConfig(pluginId)) {
try {
await ensureSchemaExists(pluginConfig, pluginId);
} catch (error) {
throw new Error(
`Failed to connect to the database to make sure that schema for plugin '${pluginId}' exists, ${error}`,
);
}
}
}