-
Notifications
You must be signed in to change notification settings - Fork 6
/
init_wallet_dbs.py
64 lines (57 loc) · 2.34 KB
/
init_wallet_dbs.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
import json
import sys
import os
def read_appsettings(filename):
import io
with io.open(filename, "r", encoding="utf-8-sig") as json_file:
return json.load(json_file)
def get_mysql_details(data):
mysql = data["Wallet"]["MySql"]
return (mysql["Host"], mysql["User"], mysql["Password"])
def get_db_names(data):
db_names = data["Wallet"]["DbNames"]
chain_assets = data["Wallet"]["ChainAssetSettings"]
chain_db_names = []
fiat_db_names = []
for key in db_names.keys():
if key in chain_assets.keys():
chain_db_names.append(db_names[key])
else:
fiat_db_names.append(db_names[key])
return (chain_db_names, fiat_db_names)
def init_db(project, startup_project, context, host, db_name, user, password):
print(":: create db '%s'.." % db_name)
os.environ["CONNECTION_STRING"] = "host=%s;database=%s;uid=%s;password=%s;" % (host, db_name, user, password)
print(" > %s" % os.environ["CONNECTION_STRING"])
cmd = "/opt/dotnet/dotnet-ef database update --project %s --startup-project %s --context %s" % (project, startup_project, context)
print(" > %s" % cmd)
res = os.system(cmd)
if res != 0:
sys.exit(res)
def init_dbs(project, startup_project, host, user, password, chain_db_names, fiat_db_names):
#os.chdir(directory)
os.environ["DB_TYPE"] = "mysql"
for db_name in chain_db_names:
init_db(project, startup_project, "WalletContext", host, db_name, user, password)
for db_name in fiat_db_names:
init_db(project, startup_project, "FiatWalletContext", host, db_name, user, password)
if __name__ == "__main__":
filename = sys.argv[1]
project = sys.argv[2]
startup_project = sys.argv[3]
print(filename)
print(project)
print(startup_project)
if not os.path.exists(filename):
print("Error: %s does not exist" % filename)
sys.exit(1)
if not os.path.exists(project):
print("Error: %s does not exist" % project)
sys.exit(1)
if not os.path.exists(startup_project):
print("Error: %s does not exist" % startup_project)
sys.exit(1)
data = read_appsettings(filename)
host, user, password = get_mysql_details(data)
chain_db_names, fiat_db_names = get_db_names(data)
init_dbs(project, startup_project, host, user, password, chain_db_names, fiat_db_names)