def _execute(db, to_run, interactive=True, commit=True):
if interactive: print()
try:
with db.atomic() as txn:
for sql, params in to_run:
if interactive or DEBUG: print_sql(' %s; %s' % (sql, params or ''))
if sql.strip().startswith('--'): continue
db.execute_sql(sql, params)
if interactive:
print()
print(
(colorama.Style.BRIGHT + 'SUCCESS!' + colorama.Style.RESET_ALL) if commit else 'TEST PASSED - ROLLING BACK',
colorama.Style.DIM + '-',
'https://github.com/keredson/peewee-db-evolve' + colorama.Style.RESET_ALL
)
print()
if not commit:
txn.rollback()
except Exception as e:
print()
print('------------------------------------------')
print(colorama.Style.BRIGHT + colorama.Fore.RED + ' SQL EXCEPTION - ROLLING BACK ALL CHANGES' + colorama.Style.RESET_ALL)
print('------------------------------------------')
print()
raise e
评论列表
文章目录