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 create(): # 创建好了,不能添加新字段 db.create_all() return '表创建成功'
def create_table(): # 生成表 db.create_all() return '表创建成功'