migrations.py 文件源码

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

项目:Enibar 作者: ENIB 项目源码 文件源码
def execute_sql_file(filename):
    """ Since mysql can't rollback any CREATE/ALTER/DROP instruction,
    do a full backup before starting the migration and if it fails, and reapply
    it if it fails
    """
    with database.Database() as db, open(filename) as fd:
        if not db.transaction():
            print("Failed to start the migration")
            sys.exit(1)

        cursor = QtSql.QSqlQuery(db)
        for statement in sqlparse.split(fd.read()):
            if not statement:
                continue

            if not cursor.exec_(statement):
                db.rollback()
                print(cursor.lastError().text())
                break
        else:
            db.commit()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号