forked from C64Axel/MonsterBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbupdate.py
executable file
·53 lines (43 loc) · 1.36 KB
/
dbupdate.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
#! /usr/bin/python
import pymysql.cursors
import sys
from configobj import ConfigObj
from lib.dbcheck import check_db_version
def migrate_db():
version = check_db_version(cursor)
print("Old Version {}".format(version))
# if version < 1:
# cursor.execute("alter table `user` drop column 'paused'")
# cursor.execute("update dbversion set version = '1'")
version = check_db_version(cursor)
print("New Version {}".format(version))
print("Migration complete")
############# MAIN ################
# read inifile
try:
inifile = sys.argv[1]
config = ConfigObj(inifile)
token=config.get('token')
db = config['dbname']
dbhost = config['dbhost']
dbport = config.get('dbport', '3306')
dbuser = config['dbuser']
dbpassword = config['dbpassword']
except:
print("Inifile not given")
quit()
# connect to database
#
try:
connection = pymysql.connect(host=dbhost,
user=dbuser,
password=dbpassword,
db=db,
port=int(dbport),
charset='utf8mb4',
autocommit='True')
cursor = connection.cursor()
except:
print("can not connect to database")
quit()
migrate_db()