예제 #1
0
def init(with_testdb):
    """
    Initialize the database.

    :param with_testdb: Create a test database
    :return: None
    """
    db.drop_all()
    db.create_all()

    if with_testdb:
        db_uri = '{0}_test'.format(app.config['SQLALCHEMY_DATABASE_URI'])

        if not database_exists(db_uri):
            create_database(db_uri)

    return None
예제 #2
0
def db(app):
    """
    Setup our database, this only gets executed once per session.

    :param app: Pytest fixture
    :return: SQLAlchemy database session
    """
    _db.drop_all()
    _db.create_all()

    # Create a single user because a lot of tests do not mutate this user.
    # It will result in faster tests.
    params = {
        'role': 'admin',
        'email': '*****@*****.**',
        'password': '******'
    }

    admin = User(**params)

    _db.session.add(admin)
    _db.session.commit()

    return _db
예제 #3
0
파일: manage.py 프로젝트: FateGitHub/GZ
def drop():
    if prompt_bool('是否删除表'):
        db.drop_all()
        return '删数据库跑路'
    else:
        return '谢谢放过'
예제 #4
0
파일: stu.py 프로젝트: FateGitHub/GZ
def drop_table():
    # 删除表
    db.drop_all()
    return '表删除成功'