File tree Expand file tree Collapse file tree 3 files changed +314
-294
lines changed Expand file tree Collapse file tree 3 files changed +314
-294
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,24 @@ def db_connect():
32
32
return conn
33
33
34
34
35
+ def db_connect_root ():
36
+ base_dir = os .path .dirname (os .path .abspath (__file__ ))
37
+ config_path = os .path .join (base_dir , "mysql_config.json" )
38
+ with open (config_path ) as f :
39
+ mysql_cred = json .load (f )
40
+
41
+ conn = pymysql .connect (
42
+ host = mysql_cred ["servername" ],
43
+ user = mysql_cred ["username" ],
44
+ password = mysql_cred ["password" ],
45
+ charset = "utf8mb4" ,
46
+ cursorclass = pymysql .cursors .DictCursor ,
47
+ autocommit = True ,
48
+ )
49
+
50
+ return (conn , mysql_cred ["dbname" ])
51
+
52
+
35
53
def get_checksum_props (checkcode , checksum ):
36
54
checksize = 0
37
55
checktype = checkcode
Original file line number Diff line number Diff line change 23
23
user_integrity_check ,
24
24
db_connect ,
25
25
create_log ,
26
+ db_connect_root ,
26
27
)
27
28
from collections import defaultdict
29
+ from schema import init_database
28
30
29
31
app = Flask (__name__ )
30
32
@@ -79,21 +81,13 @@ def index():
79
81
@app .route ("/clear_database" , methods = ["POST" ])
80
82
def clear_database ():
81
83
try :
82
- conn = db_connect ()
84
+ ( conn , db_name ) = db_connect_root ()
83
85
with conn .cursor () as cursor :
84
- cursor .execute ("SET FOREIGN_KEY_CHECKS = 0;" )
85
- cursor .execute ("TRUNCATE TABLE filechecksum" )
86
- cursor .execute ("TRUNCATE TABLE history" )
87
- cursor .execute ("TRUNCATE TABLE transactions" )
88
- cursor .execute ("TRUNCATE TABLE queue" )
89
- cursor .execute ("TRUNCATE TABLE file" )
90
- cursor .execute ("TRUNCATE TABLE fileset" )
91
- cursor .execute ("TRUNCATE TABLE game" )
92
- cursor .execute ("TRUNCATE TABLE engine" )
93
- cursor .execute ("TRUNCATE TABLE log" )
94
- cursor .execute ("SET FOREIGN_KEY_CHECKS = 1;" )
86
+ cursor .execute (f"DROP DATABASE IF EXISTS { db_name } " )
95
87
conn .commit ()
96
- print ("DATABASE CLEARED" )
88
+ print ("DATABASE DROPPED" )
89
+ init_database ()
90
+ print ("DATABASE INITIALISED" )
97
91
except Exception as e :
98
92
print (f"Error clearing database: { e } " )
99
93
finally :
You can’t perform that action at this time.
0 commit comments