-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
35 lines (27 loc) · 1.07 KB
/
init.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
import logging
from schafkopf.database.data_model import Base
from schafkopf.database.queries import insert_default_punkteconfig, insert_user
from schafkopf.database.session import Sessions
from schafkopf.utils.settings_utils import get_database_url, get_init_username, get_init_password
logging.getLogger().setLevel(logging.INFO)
def database_init():
engine = Sessions.get_engine()
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
# Note: here you can change the default configuration of points (currently: 50-20-10)
insert_default_punkteconfig()
insert_default_username_password()
logging.info(f'Database in {get_database_url()} created successfully')
def insert_default_username_password():
try:
username = get_init_username()
except ValueError:
username = None
try:
password = get_init_password()
except ValueError:
password = None
if username is not None and password is not None:
insert_user(username=username, password=password)
if __name__ == '__main__':
database_init()