def run(self, alembic_ini=None): if flask.current_app.config['SQLALCHEMY_DATABASE_URI'].startswith( 'sqlite'): # strip sqlite:/// datadir_name = os.path.dirname( flask.current_app.config['SQLALCHEMY_DATABASE_URI'] [len('sqlite:///'):]) if not os.path.exists(datadir_name): os.makedirs(datadir_name) db.create_all()
def test_db(app): """ Setup database, this only gets executed once per module. :param app: Pytest fixture :return: SQLAlchemy database session """ _db.drop_all() _db.create_all() yield _db _db.session.remove() _db.drop_all()
primary_key=True, nullable=False) def __repr__(self) -> str: ''' :return: lấy ra được id 1 thay vi` <phieunhapsach 1> ''' return repr(self.phieuNhap_id) class PhieuThuTienNo(db.Model): __tablename__ = "PhieuThuTienNo" id = Column(Integer, primary_key=True, autoincrement=True) ngayThu = Column(Date, nullable=False) soTien = Column(Numeric, nullable=False) khachHang_id = Column(Integer, ForeignKey(KhachHang.id), nullable=False) class KhachHangNo(db.Model): __tablename__ = "KhachHangNo" ngayNo = Column(Date, nullable=False) soTien = Column(Numeric, nullable=False) khachHang_id = Column(Integer, ForeignKey(KhachHang.id), primary_key=True, nullable=False) if __name__ == '__main__': db.create_all()
from demo import app, db db.create_all()
def initdb(drop): if drop: db.drop_all() db.create_all() click.echo('Initialized database.')
def setUp(self): """Initialize Database""" db.create_all()
def recreate_db(): db.session.remove() db.drop_all() db.create_all()
def recreate_db(): """Recreate database.""" print("Recreating database.") db.drop_all() db.create_all() db.session.commit()