Update database migration log levels

This commit is contained in:
nymkappa 2022-02-21 23:57:44 +09:00
parent 938a978900
commit 976017dbef
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
2 changed files with 16 additions and 16 deletions

View File

@ -15,13 +15,13 @@ class DatabaseMigration {
* Entry point * Entry point
*/ */
public async $initializeOrMigrateDatabase(): Promise<void> { public async $initializeOrMigrateDatabase(): Promise<void> {
logger.info('MIGRATIONS: Running migrations'); logger.debug('MIGRATIONS: Running migrations');
await this.$printDatabaseVersion(); await this.$printDatabaseVersion();
// First of all, if the `state` database does not exist, create it so we can track migration version // First of all, if the `state` database does not exist, create it so we can track migration version
if (!await this.$checkIfTableExists('state')) { if (!await this.$checkIfTableExists('state')) {
logger.info('MIGRATIONS: `state` table does not exist. Creating it.'); logger.debug('MIGRATIONS: `state` table does not exist. Creating it.');
try { try {
await this.$createMigrationStateTable(); await this.$createMigrationStateTable();
} catch (e) { } catch (e) {
@ -29,7 +29,7 @@ class DatabaseMigration {
await sleep(10000); await sleep(10000);
process.exit(-1); process.exit(-1);
} }
logger.info('MIGRATIONS: `state` table initialized.'); logger.debug('MIGRATIONS: `state` table initialized.');
} }
let databaseSchemaVersion = 0; let databaseSchemaVersion = 0;
@ -41,10 +41,10 @@ class DatabaseMigration {
process.exit(-1); process.exit(-1);
} }
logger.info('MIGRATIONS: Current state.schema_version ' + databaseSchemaVersion); logger.debug('MIGRATIONS: Current state.schema_version ' + databaseSchemaVersion);
logger.info('MIGRATIONS: Latest DatabaseMigration.version is ' + DatabaseMigration.currentVersion); logger.debug('MIGRATIONS: Latest DatabaseMigration.version is ' + DatabaseMigration.currentVersion);
if (databaseSchemaVersion >= DatabaseMigration.currentVersion) { if (databaseSchemaVersion >= DatabaseMigration.currentVersion) {
logger.info('MIGRATIONS: Nothing to do.'); logger.debug('MIGRATIONS: Nothing to do.');
return; return;
} }
@ -58,10 +58,10 @@ class DatabaseMigration {
} }
if (DatabaseMigration.currentVersion > databaseSchemaVersion) { if (DatabaseMigration.currentVersion > databaseSchemaVersion) {
logger.info('MIGRATIONS: Upgrading datababse schema'); logger.notice('MIGRATIONS: Upgrading datababse schema');
try { try {
await this.$migrateTableSchemaFromVersion(databaseSchemaVersion); await this.$migrateTableSchemaFromVersion(databaseSchemaVersion);
logger.info(`MIGRATIONS: OK. Database schema have been migrated from version ${databaseSchemaVersion} to ${DatabaseMigration.currentVersion} (latest version)`); logger.notice(`MIGRATIONS: OK. Database schema have been migrated from version ${databaseSchemaVersion} to ${DatabaseMigration.currentVersion} (latest version)`);
} catch (e) { } catch (e) {
logger.err('MIGRATIONS: Unable to migrate database, aborting. ' + e); logger.err('MIGRATIONS: Unable to migrate database, aborting. ' + e);
} }
@ -149,10 +149,10 @@ class DatabaseMigration {
WHERE table_schema=DATABASE() AND table_name='statistics' AND index_name='added';`; WHERE table_schema=DATABASE() AND table_name='statistics' AND index_name='added';`;
const [rows] = await this.$executeQuery(connection, query, true); const [rows] = await this.$executeQuery(connection, query, true);
if (rows[0].hasIndex === 0) { if (rows[0].hasIndex === 0) {
logger.info('MIGRATIONS: `statistics.added` is not indexed'); logger.debug('MIGRATIONS: `statistics.added` is not indexed');
this.statisticsAddedIndexed = false; this.statisticsAddedIndexed = false;
} else if (rows[0].hasIndex === 1) { } else if (rows[0].hasIndex === 1) {
logger.info('MIGRATIONS: `statistics.added` is already indexed'); logger.debug('MIGRATIONS: `statistics.added` is already indexed');
this.statisticsAddedIndexed = true; this.statisticsAddedIndexed = true;
} }
} catch (e) { } catch (e) {
@ -170,7 +170,7 @@ class DatabaseMigration {
*/ */
private async $executeQuery(connection: PoolConnection, query: string, silent: boolean = false): Promise<any> { private async $executeQuery(connection: PoolConnection, query: string, silent: boolean = false): Promise<any> {
if (!silent) { if (!silent) {
logger.info('MIGRATIONS: Execute query:\n' + query); logger.debug('MIGRATIONS: Execute query:\n' + query);
} }
return connection.query<any>({ sql: query, timeout: this.queryTimeout }); return connection.query<any>({ sql: query, timeout: this.queryTimeout });
} }
@ -282,9 +282,9 @@ class DatabaseMigration {
const connection = await DB.pool.getConnection(); const connection = await DB.pool.getConnection();
try { try {
const [rows] = await this.$executeQuery(connection, 'SELECT VERSION() as version;', true); const [rows] = await this.$executeQuery(connection, 'SELECT VERSION() as version;', true);
logger.info(`MIGRATIONS: Database engine version '${rows[0].version}'`); logger.debug(`MIGRATIONS: Database engine version '${rows[0].version}'`);
} catch (e) { } catch (e) {
logger.info(`MIGRATIONS: Could not fetch database engine version. ` + e); logger.debug(`MIGRATIONS: Could not fetch database engine version. ` + e);
} }
connection.release(); connection.release();
} }
@ -427,7 +427,7 @@ class DatabaseMigration {
try { try {
for (const table of tables) { for (const table of tables) {
if (!allowedTables.includes(table)) { if (!allowedTables.includes(table)) {
logger.info(`Table ${table} cannot to be re-indexed (not allowed)`); logger.debug(`Table ${table} cannot to be re-indexed (not allowed)`);
continue; continue;
}; };
@ -435,7 +435,7 @@ class DatabaseMigration {
if (table === 'hashrates') { if (table === 'hashrates') {
await this.$executeQuery(connection, 'UPDATE state set number = 0 where name = "last_hashrates_indexing"', true); await this.$executeQuery(connection, 'UPDATE state set number = 0 where name = "last_hashrates_indexing"', true);
} }
logger.info(`Table ${table} has been truncated`); logger.notice(`Table ${table} has been truncated`);
} }
} catch (e) { } catch (e) {
logger.warn(`Unable to erase indexed data`); logger.warn(`Unable to erase indexed data`);

View File

@ -173,7 +173,7 @@ class Server {
await blocks.$generateBlockDatabase(); await blocks.$generateBlockDatabase();
await mining.$generateNetworkHashrateHistory(); await mining.$generateNetworkHashrateHistory();
} catch (e) { } catch (e) {
logger.info(`Unable to run indexing right now, trying again later. ` + e); logger.err(`Unable to run indexing right now, trying again later. ` + e);
} }
} }