diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 3140ea358..13cffd755 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -1012,26 +1012,16 @@ class DatabaseMigration { ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`; } - public async $truncateIndexedData(tables: string[]) { - const allowedTables = ['blocks', 'hashrates', 'prices']; + public async $blocksReindexingTruncate(): Promise { + logger.warn(`Truncating pools, blocks and hashrates for re-indexing (using '--reindex-blocks'). You can cancel this command within 5 seconds`); + await Common.sleep$(5000); - try { - for (const table of tables) { - if (!allowedTables.includes(table)) { - logger.debug(`Table ${table} cannot to be re-indexed (not allowed)`); - continue; - } - - await this.$executeQuery(`TRUNCATE ${table}`, true); - if (table === 'hashrates') { - await this.$executeQuery('UPDATE state set number = 0 where name = "last_hashrates_indexing"', true); - } - logger.notice(`Table ${table} has been truncated`); - } - } catch (e) { - logger.warn(`Unable to erase indexed data`); - } - } + await this.$executeQuery(`TRUNCATE blocks`); + await this.$executeQuery(`TRUNCATE hashrates`); + await this.$executeQuery('DELETE FROM `pools`'); + await this.$executeQuery('ALTER TABLE pools AUTO_INCREMENT = 1'); + await this.$executeQuery(`UPDATE state SET string = NULL WHERE name = 'pools_json_sha'`); +} private async $convertCompactCpfpTables(): Promise { try { diff --git a/backend/src/index.ts b/backend/src/index.ts index 6ea3ddc43..e96d7e4da 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -84,11 +84,8 @@ class Server { if (config.DATABASE.ENABLED) { await DB.checkDbConnection(); try { - if (process.env.npm_config_reindex !== undefined) { // Re-index requests - const tables = process.env.npm_config_reindex.split(','); - logger.warn(`Indexed data for "${process.env.npm_config_reindex}" tables will be erased in 5 seconds (using '--reindex')`); - await Common.sleep$(5000); - await databaseMigration.$truncateIndexedData(tables); + if (process.env.npm_config_reindex_blocks === 'true') { // Re-index requests + await databaseMigration.$blocksReindexingTruncate(); } await databaseMigration.$initializeOrMigrateDatabase(); if (Common.indexingEnabled()) {