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
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
def drop(): if prompt_bool('是否删除表'): db.drop_all() return '删数据库跑路' else: return '谢谢放过'
def drop_table(): # 删除表 db.drop_all() return '表删除成功'