Make migrations object required

Signed-off-by: Marcus Eide <eide@spotify.com>
This commit is contained in:
Marcus Eide
2021-12-02 14:19:02 +01:00
parent 70c46a708b
commit 7b61f2c3b6
11 changed files with 17 additions and 14 deletions
@@ -63,7 +63,7 @@ describe('DatabaseManager', () => {
const database = DatabaseManager.fromConfig(config);
const client = database.forPlugin('test');
expect(client.migrations?.apply).toBe(true);
expect(client.migrations.apply).toBe(true);
});
it('handles migrations options', () => {
@@ -73,7 +73,7 @@ describe('DatabaseManager', () => {
});
const client = database.forPlugin('test');
expect(client.migrations?.apply).toBe(false);
expect(client.migrations.apply).toBe(false);
});
});
@@ -37,7 +37,7 @@ function pluginPath(pluginId: string): string {
}
type Options = {
migrations?: PluginDatabaseManager['migrations'];
migrations: PluginDatabaseManager['migrations'];
};
/** @public */
@@ -78,15 +78,15 @@ export class DatabaseManager {
*/
forPlugin(pluginId: string): PluginDatabaseManager {
const _this = this;
const defaultMigrationOptions = {
apply: true,
};
return {
getClient(): Promise<Knex> {
return _this.getDatabase(pluginId);
},
migrations: _this.options?.migrations ?? defaultMigrationOptions,
migrations: {
apply: true,
..._this.options?.migrations,
},
};
}
@@ -32,9 +32,9 @@ export interface PluginDatabaseManager {
getClient(): Promise<Knex>;
/**
* This optional property is used to control the behavior of database migrations.
* 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.
@@ -33,6 +33,7 @@ describe('TaskScheduler', () => {
const databaseManager: Partial<DatabaseManager> = {
forPlugin: () => ({
getClient: async () => knex,
migrations: { apply: true },
}),
};
return databaseManager as DatabaseManager;
@@ -56,6 +56,7 @@ 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 },
database: { getClient: async () => db, migrations: { apply: true } },
config: config,
});
@@ -49,7 +49,7 @@ describe('CatalogBuilder', () => {
};
const env: CatalogEnvironment = {
logger: getVoidLogger(),
database: { getClient: async () => db },
database: { getClient: async () => db, migrations: { apply: true } },
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.apply) {
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 },
database: { getClient: () => db, migrations: { apply: true } },
config,
reader,
});
@@ -54,7 +54,7 @@ export async function startStandaloneServer(
logger.debug('Starting application server...');
const router = await createRouter({
database: { getClient: async () => db },
database: { getClient: async () => db, migrations: { apply: true } },
config,
discovery: SingleHostDiscovery.fromConfig(config),
urlReader: UrlReaders.default({ logger, config }),
@@ -53,6 +53,7 @@ describe('Tech Insights router tests', () => {
},
}) as unknown as Promise<Knex>;
},
migrations: { apply: true },
},
logger: getVoidLogger(),
factRetrievers: [],