forked from bitcoinwspectrum/SpectrumBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py
71 lines (65 loc) · 2.52 KB
/
database.py
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
import pymysql.cursors
import warnings
from utils import parsing, output
config = parsing.parse_json('config.json')["mysql"]
host = config["db_host"]
try:
port = int(config["db_port"])
except KeyError:
port = 3306
db_user = config["db_user"]
db_pass = config["db_pass"]
db = config["db"]
connection = pymysql.connect(
host=host,
port=port,
user=db_user,
password=db_pass,
db=db)
cursor = connection.cursor(pymysql.cursors.DictCursor)
#cursor.execute("DROP DATABASE IF EXISTS {};".format(database))
#cursor.execute("CREATE DATABASE IF NOT EXISTS {};".format(database))
#conn.commit()
#cursor.execute("USE {};".format(database))
def run():
with warnings.catch_warnings():
warnings.simplefilter('ignore')
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
snowflake_pk BIGINT UNSIGNED NOT NULL,
balance DECIMAL(20, 8) NOT NULL,
balance_unconfirmed DECIMAL(20, 8) NOT NULL,
address VARCHAR(34) NOT NULL,
PRIMARY KEY (snowflake_pk)
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS deposit (
snowflake_fk BIGINT UNSIGNED NOT NULL,
amount DECIMAL(20, 8) NOT NULL,
txid VARCHAR(256) NOT NULL,
status VARCHAR(20) NOT NULL,
FOREIGN KEY (snowflake_fk) REFERENCES users(snowflake_pk)
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS withdrawal (
snowflake_fk BIGINT UNSIGNED NOT NULL,
amount DECIMAL(20, 8) NOT NULL,
txid VARCHAR(256) NOT NULL,
FOREIGN KEY (snowflake_fk) REFERENCES users(snowflake_pk)
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS tip (
snowflake_from_fk BIGINT UNSIGNED NOT NULL,
snowflake_to_fk BIGINT UNSIGNED NOT NULL,
amount DECIMAL(20, 8) NOT NULL,
FOREIGN KEY (snowflake_from_fk) REFERENCES users(snowflake_pk),
FOREIGN KEY (snowflake_to_fk) REFERENCES users(snowflake_pk)
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS server (
server_id VARCHAR(18) NOT NULL,
enable_soak TINYINT(1) NOT NULL,
PRIMARY KEY (server_id)
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS channel (
channel_id VARCHAR(18) NOT NULL,
server_id VARCHAR(18) NOT NULL,
enabled TINYINT(1) NOT NULL,
FOREIGN KEY (server_id) REFERENCES server(server_id),
PRIMARY KEY (channel_id)
)""")