Drop legacy blocks table during migration - Fix linter issues

This commit is contained in:
nymkappa 2022-01-20 17:20:02 +09:00
parent b8410f00d9
commit aa457e316b
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
5 changed files with 15 additions and 14 deletions

View File

@ -17,6 +17,6 @@ sudo npm install -g ts-node nodemon
> Note: You can find your npm global binary folder using `npm -g bin`, where nodemon will be installed.
```
nodemon src/index.ts --ignore cache/
nodemon src/index.ts --ignore cache/ --ignore pools.json
```

View File

@ -124,15 +124,15 @@ class Blocks {
const pools: PoolTag[] = await poolsRepository.$getPools();
for (let i = 0; i < pools.length; ++i) {
if (address !== undefined) {
let addresses: string[] = JSON.parse(pools[i].addresses);
const addresses: string[] = JSON.parse(pools[i].addresses);
if (addresses.indexOf(address) !== -1) {
return pools[i];
}
}
let regexes: string[] = JSON.parse(pools[i].regexes);
const regexes: string[] = JSON.parse(pools[i].regexes);
for (let y = 0; y < regexes.length; ++y) {
let match = asciiScriptSig.match(regexes[y]);
const match = asciiScriptSig.match(regexes[y]);
if (match !== null) {
return pools[i];
}

View File

@ -87,6 +87,7 @@ class DatabaseMigration {
await this.$executeQuery(connection, this.getCreatePoolsTableQuery(), await this.$checkIfTableExists('pools'));
}
if (databaseSchemaVersion < 4) {
await this.$executeQuery(connection, 'DROP table blocks;');
await this.$executeQuery(connection, this.getCreateBlocksTableQuery(), await this.$checkIfTableExists('blocks'));
}
connection.release();

View File

@ -38,7 +38,7 @@ class BlocksRepository {
await connection.query(query, params);
} catch (e) {
logger.err('$updateBlocksDatabase() error' + (e instanceof Error ? e.message : e));
logger.err('$saveBlockInDatabase() error' + (e instanceof Error ? e.message : e));
}
connection.release();

View File

@ -1,5 +1,5 @@
import { DB } from "../database";
import { PoolInfo, PoolTag } from "../mempool.interfaces"
import { DB } from '../database';
import { PoolInfo, PoolTag } from '../mempool.interfaces';
class PoolsRepository {
/**
@ -7,7 +7,7 @@ class PoolsRepository {
*/
public async $getPools(): Promise<PoolTag[]> {
const connection = await DB.pool.getConnection();
const [rows] = await connection.query("SELECT * FROM pools;");
const [rows] = await connection.query('SELECT * FROM pools;');
connection.release();
return <PoolTag[]>rows;
}
@ -17,7 +17,7 @@ class PoolsRepository {
*/
public async $getUnknownPool(): Promise<PoolTag> {
const connection = await DB.pool.getConnection();
const [rows] = await connection.query("SELECT * FROM pools where name = 'Unknown'");
const [rows] = await connection.query('SELECT * FROM pools where name = "Unknown"');
connection.release();
return <PoolTag>rows[0];
}
@ -25,7 +25,7 @@ class PoolsRepository {
/**
* Get basic pool info and block count
*/
public async $getPoolsInfo(interval: string = "100 YEARS"): Promise<PoolInfo[]> {
public async $getPoolsInfo(interval: string = '100 YEARS'): Promise<PoolInfo[]> {
const connection = await DB.pool.getConnection();
const [rows] = await connection.query(`
SELECT COUNT(height) as blockCount, pool_id as poolId, pools.name as name, pools.link as link