config = new Config(process.env.NODE_ENV);
logger = new Logger(config);
db = new DB(logger, config);
- await db.schemaCheck();
+ await db.initialize();
service = new Service(logger, db, config);
http.createServer((req, res) => {
/**
- * Validate schema compatibility.
- * Ensure this is called immediately after instantiating a DB instance,
- * as some engines also finish initialization and validation here, which
- * was easier than wrangling async calls in constructor.
- * In light of this behavior, this method could be named better.
- */
- async schemaCheck() {
- const _scope = _fileScope('schemaCheck');
+ * Perform tasks needed to prepare database for use. Ensure this is called
+ * after construction, and before any other database activity.
+ * At the minimum, this will validate a compatible schema is present and usable.
+ * Some engines will also perform other initializations or async actions which
+ * are easier handled outside the constructor.
+ */
+ async initialize() {
+ const _scope = _fileScope('initialize');
const currentSchema = await this._currentSchema();
const current = svh.schemaVersionObjectToNumber(currentSchema);
}
- async schemaCheck(applyMigrations = true) {
- const _scope = _fileScope('schemaCheck');
+ async initialize(applyMigrations = true) {
+ const _scope = _fileScope('initialize');
this.logger.debug(_scope, 'called', { applyMigrations });
if (applyMigrations) {
await this._initTables();
}
- await super.schemaCheck();
+ await super.initialize();
}
});
}); // _ensureTypes
- describe('schemaCheck', function () {
+ describe('initialize', function () {
let currentSchema;
beforeEach(function () {
currentSchema = {
sinon.stub(db, '_currentSchema').resolves(currentSchema);
});
it('covers success', async function () {
- await db.schemaCheck();
+ await db.initialize();
});
it('covers failure', async function() {
db.schemaVersionsSupported = {
},
};
try {
- await db.schemaCheck();
+ await db.initialize();
assert.fail('did not get expected exception');
} catch (e) {
assert(e instanceof DBErrors.MigrationNeeded);
}
});
- }); // schemaCheck
+ }); // initialize
describe('_topicDefaults', function () {
let topic;
// eslint-disable-next-line security/detect-non-literal-require
DB = require(i.module);
db = new DB(stubLogger, i.config);
- await db.schemaCheck();
+ await db.initialize();
await db._purgeTables(true);
});
after(async function () {
});
}); // _initTables
- describe('schemaCheck', function () {
+ describe('initialize', function () {
it('passes supported version', async function () {
const version = { major: 1, minor: 0, patch: 0 };
sinon.stub(db.db, 'one').resolves(version);
- await db.schemaCheck(false);
+ await db.initialize(false);
});
it('fails low version', async function () {
const version = { major: 0, minor: 0, patch: 0 };
sinon.stub(db.db, 'one').resolves(version);
try {
- await db.schemaCheck(false);
+ await db.initialize(false);
assert.fail(noExpectedException);
} catch (e) {
assert(e instanceof DBErrors.MigrationNeeded);
const version = { major: 100, minor: 100, patch: 100 };
sinon.stub(db.db, 'one').resolves(version);
try {
- await db.schemaCheck(false);
+ await db.initialize(false);
assert.fail(noExpectedException);
} catch (e) {
assert(e instanceof DBErrors.MigrationNeeded);
sinon.stub(db.db, 'multiResult');
sinon.stub(db, '_currentSchema').resolves(db.schemaVersionsSupported.max);
sinon.stub(db.db, 'one').resolves(db.schemaVersionsSupported.max);
- await db.schemaCheck();
+ await db.initialize();
});
- }); // schemaCheck
+ }); // initialize
describe('healthCheck', function () {
beforeEach(function () {
'authenticationGet',
'authenticationUpsert',
'healthCheck',
- 'schemaCheck',
+ 'initialize',
'subscriptionsByTopicId',
'subscriptionCountByTopicUrl',
'subscriptionDelete',