dbmanager.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:yt2audiobot 作者: gise88 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号