Make optional

Signed-off-by: Marcus Eide <eide@spotify.com>
This commit is contained in:
Marcus Eide
2021-12-07 12:44:16 +01:00
parent 5c1840c16e
commit dac55f3cc7
12 changed files with 18 additions and 24 deletions
+4 -4
View File
@@ -183,7 +183,7 @@ export class DatabaseManager {
// @public
export type DatabaseManagerOptions = {
migrations: PluginDatabaseManager['migrations'];
migrations?: PluginDatabaseManager['migrations'];
};
// @public (undocumented)
@@ -403,8 +403,8 @@ export type PluginCacheManager = {
// @public
export interface PluginDatabaseManager {
getClient(): Promise<Knex>;
migrations: {
apply: boolean;
migrations?: {
skip?: boolean;
};
}
@@ -656,5 +656,5 @@ export function useHotMemoize<T>(_module: NodeModule, valueFactory: () => T): T;
// Warnings were encountered during analysis:
//
// src/database/types.d.ts:26:12 - (tsdoc-undefined-tag) The TSDoc tag "@default" is not defined in this configuration
// src/database/types.d.ts:23:12 - (tsdoc-undefined-tag) The TSDoc tag "@default" is not defined in this configuration
```
@@ -63,17 +63,17 @@ describe('DatabaseManager', () => {
const database = DatabaseManager.fromConfig(config);
const client = database.forPlugin('test');
expect(client.migrations.apply).toBe(true);
expect(client.migrations?.skip).toBe(false);
});
it('handles migrations options', () => {
const config = new ConfigReader(backendConfig);
const database = DatabaseManager.fromConfig(config, {
migrations: { apply: false },
migrations: { skip: true },
});
const client = database.forPlugin('test');
expect(client.migrations.apply).toBe(false);
expect(client.migrations?.skip).toBe(true);
});
});
@@ -42,7 +42,7 @@ function pluginPath(pluginId: string): string {
* @public
*/
export type DatabaseManagerOptions = {
migrations: PluginDatabaseManager['migrations'];
migrations?: PluginDatabaseManager['migrations'];
};
/** @public */
@@ -92,7 +92,7 @@ export class DatabaseManager {
return _this.getDatabase(pluginId);
},
migrations: {
apply: true,
skip: false,
..._this.options?.migrations,
},
};
@@ -34,16 +34,13 @@ export interface PluginDatabaseManager {
/**
* This property is used to control the behavior of database migrations.
*/
migrations: {
migrations?: {
/**
* apply can be used to determine if database migrations
* should be performed.
* skip database migrations. Useful if connecting to a read-only database.
*
* Useful if connecting to a read-only database.
*
* @default true
* @default false
*/
apply: boolean;
skip?: boolean;
};
}
@@ -33,7 +33,6 @@ describe('TaskScheduler', () => {
const databaseManager: Partial<DatabaseManager> = {
forPlugin: () => ({
getClient: async () => knex,
migrations: { apply: true },
}),
};
return databaseManager as DatabaseManager;
@@ -56,7 +56,6 @@ export async function startStandaloneServer(
async getClient() {
return database;
},
migrations: { apply: true },
},
discovery,
});
@@ -52,7 +52,7 @@ export async function startStandaloneServer(
const router = await createRouter({
logger,
database: { getClient: async () => db, migrations: { apply: true } },
database: { getClient: async () => db },
config: config,
});
@@ -49,7 +49,7 @@ describe('CatalogBuilder', () => {
};
const env: CatalogEnvironment = {
logger: getVoidLogger(),
database: { getClient: async () => db, migrations: { apply: true } },
database: { getClient: async () => db },
config: new ConfigReader({}),
reader,
};
@@ -336,7 +336,7 @@ export class NextCatalogBuilder {
const parser = this.parser || defaultEntityDataParser;
const dbClient = await database.getClient();
if (database.migrations.apply) {
if (!database.migrations?.skip) {
logger.info('Performing database migration');
await applyDatabaseMigrations(dbClient);
}
@@ -46,7 +46,7 @@ export async function startStandaloneServer(
logger.debug('Creating application...');
const builder = new CatalogBuilder({
logger,
database: { getClient: () => db, migrations: { apply: true } },
database: { getClient: () => db },
config,
reader,
});
@@ -54,7 +54,7 @@ export async function startStandaloneServer(
logger.debug('Starting application server...');
const router = await createRouter({
database: { getClient: async () => db, migrations: { apply: true } },
database: { getClient: async () => db },
config,
discovery: SingleHostDiscovery.fromConfig(config),
urlReader: UrlReaders.default({ logger, config }),
@@ -53,7 +53,6 @@ describe('Tech Insights router tests', () => {
},
}) as unknown as Promise<Knex>;
},
migrations: { apply: true },
},
logger: getVoidLogger(),
factRetrievers: [],