forked from othub-io/othub-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-db.js
114 lines (96 loc) · 2.67 KB
/
create-db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const mysql = require('mysql2/promise');
const dotenv = require('dotenv');
dotenv.config();
const connectionConfig = {
host: process.env.DBHOST,
user: process.env.DBUSER,
password: process.env.DBPASSWORD,
};
async function createDatabaseAndTables() {
try {
const connection = await mysql.createConnection(connectionConfig);
await connection.query(`CREATE DATABASE ${process.env.OTHUB_DB}`);
await connection.query(`USE ${process.env.OTHUB_DB}`);
await connection.query(`CREATE TABLE alliance_members (
adminKey VARCHAR(255),
telegramID VARCHAR(255),
botToken VARCHAR(255),
nodeGroup VARCHAR(255)
)`);
await connection.query(`CREATE TABLE command_history (
tg_id INT,
command VARCHAR(255),
date_last_used DATE
)`);
await connection.query(`CREATE TABLE commit_history (
hourly INT,
daily INT,
weekly INT,
monthly INT,
yearly INT,
total INT
)`);
await connection.query(`CREATE TABLE compliance (
nodeId INT,
warnings VARCHAR(255)
)`);
await connection.query(`CREATE TABLE monitor (
networkId INT,
ask VARCHAR(255)
)`);
await connection.query(`CREATE TABLE node_compliance (
network_id INT,
tg_id INT,
type VARCHAR(255),
warnings VARCHAR(255)
)`);
await connection.query(`CREATE TABLE node_operators (
adminKey VARCHAR(255),
keccak256hash VARCHAR(255),
telegramID VARCHAR(255),
botToken VARCHAR(255),
nodeGroup VARCHAR(255)
)`);
await connection.query(`CREATE TABLE publish_history (
hourly INT,
daily INT,
weekly INT,
monthly INT,
yearly INT,
total INT
)`);
await connection.query(`CREATE TABLE request_history (
request VARCHAR(255),
date_last_used DATE,
ip_used VARCHAR(255),
api_key VARCHAR(255)
)`);
await connection.query(`CREATE TABLE txn_header (
txn_id INT,
owner_address VARCHAR(255),
action VARCHAR(255),
type VARCHAR(255),
keywords VARCHAR(255),
timestamp TIMESTAMP,
ual VARCHAR(255),
assertionId INT,
operationId INT,
status VARCHAR(255),
data VARCHAR(255),
otp_fee DECIMAL(10,2),
trac_fee DECIMAL(10,2),
epochs INT
)`);
await connection.query(`CREATE TABLE user_header (
api_key VARCHAR(255),
admin_key VARCHAR(255),
app_name VARCHAR(255),
access VARCHAR(255)
)`);
await connection.end();
console.log('Database and tables created successfully.');
} catch (error) {
console.error('Error creating database and tables:', error);
}
}
createDatabaseAndTables();