Import mining pools into the database - Increment db schema to 3

This commit is contained in:
nymkappa
2022-01-19 18:50:52 +09:00
parent 27dc1806fb
commit 49689d8807
3 changed files with 137 additions and 3 deletions

View File

@@ -3,10 +3,10 @@ import config from '../config';
import { DB } from '../database';
import logger from '../logger';
const sleep = (ms: number) => new Promise( res => setTimeout(res, ms));
const sleep = (ms: number) => new Promise(res => setTimeout(res, ms));
class DatabaseMigration {
private static currentVersion = 2;
private static currentVersion = 3;
private queryTimeout = 120000;
private statisticsAddedIndexed = false;
@@ -83,6 +83,9 @@ class DatabaseMigration {
if (databaseSchemaVersion < 2 && this.statisticsAddedIndexed === false) {
await this.$executeQuery(connection, `CREATE INDEX added ON statistics (added);`);
}
if (databaseSchemaVersion < 3) {
await this.$executeQuery(connection, this.getCreatePoolsTableQuery(), await this.$checkIfTableExists('pools'));
}
connection.release();
} catch (e) {
connection.release();
@@ -335,6 +338,17 @@ class DatabaseMigration {
final_tx int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;`;
}
private getCreatePoolsTableQuery(): string {
return `CREATE TABLE IF NOT EXISTS pools (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(50) NOT NULL,
link varchar(255) NOT NULL,
addresses text NOT NULL,
regexes text NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`;
}
}
export default new DatabaseMigration();
export default new DatabaseMigration();