Create as well an auth table and added an option for the database name

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2021-03-03 20:29:14 +00:00
parent 08cf2dac77
commit d163f44484
2 changed files with 11 additions and 1 deletions

3
.gitignore vendored
View file

@ -4,3 +4,6 @@
# python cache
__pycache__
# config files
web/config.php

View file

@ -21,6 +21,7 @@ from common import norm, get_tile_width, get_tile, get_area_name
dbuser= ""
dbpw = ""
dbname = "worldbuild"
force = False
argc = len(sys.argv)
@ -32,6 +33,9 @@ while i < argc:
elif sys.argv[i] == "-u" or sys.argv[i] == "--user":
i += 1
dbuser = sys.argv[i]
elif sys.argv[i] == "-d" or sys.argv[i] == "--database":
i += 1
dbname = sys.argv[i]
elif sys.argv[i] == "-f" or sys.argv[i] == "--force":
force = True
elif sys.argv[i] == "-h" or sys.argv[i] == "--help":
@ -39,6 +43,7 @@ while i < argc:
print("Initializes worldbuild status db")
print("")
print("OPTIONS")
print(" -d, --database Database to be initialised. Default: worldbuild")
print(" -p, --password Database password")
print(" -u, --user Database user")
print(" -f, --force Recreates everything from scratch")
@ -67,7 +72,7 @@ states = [
]
#try:
db = pymysql.connect("localhost", dbuser, dbpw, "worldbuild")
db = pymysql.connect("localhost", dbuser, dbpw, dbname)
cursor = db.cursor()
@ -190,6 +195,8 @@ sql = ('CREATE OR REPLACE TRIGGER update_top_level '
'END IF; '
'END; ')
cursor.execute(sql)
sql = "CREATE TABLE `auth` (`id` int(11) NOT NULL AUTO_INCREMENT, `token` varchar(100) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `token` (`token`)) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4"
cursor.execute(sql)
db.commit()
#except: