-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_initial_user.py
38 lines (31 loc) · 1.09 KB
/
create_initial_user.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
'''
FastAPI Demo
Create the initial user
'''
from database.setup import session_local, engine
from database import models
from data_schemas import schemas
from utils.config_utils import get_config
from utils.user_utils import (
create_user,
set_user_admin
)
###############################################################################
CONFIG = get_config('initial_user.cfg')
INITIAL_USER_CONFIG = CONFIG['initial_user']
INITIAL_USER = schemas.UserCreate(
username=INITIAL_USER_CONFIG['username'],
first_name=INITIAL_USER_CONFIG['first_name'],
last_name=INITIAL_USER_CONFIG['last_name'],
email=INITIAL_USER_CONFIG['email'],
password=INITIAL_USER_CONFIG['password']
)
###############################################################################
def create_initial_user():
'''Create the initial user'''
session = session_local()
models.Base.metadata.create_all(bind=engine)
user = create_user(database=session, user=INITIAL_USER)
set_user_admin(database=session, user_id=user.user_id, admin=True)
###############################################################################
create_initial_user()