def initialize_db(path, root_username):
db = get_database()
_init_and_connect(db, path)
predicate = AuthorizedUser.username == root_username
try:
_check_root(predicate)
except peewee.OperationalError as e:
for table in USER_DB_MODELS:
if table.table_exists():
# some tables exist but some others don't
raise Exception('ERROR: %s - but %s exists' % (e, table.__name__))
_drop_tables(db)
_create_tables(db)
except (RootDoesNotExistException, RootIsConfiguredIncorrectlyException) as e:
user_answer = input(
'%sWarning: %s\nSomething went wrong in the database and seems to '
'be missing the root user (or something else)!\nNeed to drop all tables and '
'recreate them all.\n\nDo you want to continue? [Type \'yes\' to proceed] %s' % (
TermColors.WARNING,
str(e),
TermColors.ENDC
))
if user_answer == 'yes':
_drop_tables(db)
_create_tables(db)
else:
exit(1)
_initialize_root(predicate, root_username)
_verify_migrations(db)
评论列表
文章目录