def apply_migration(self, name, statements, fake=False):
import psycopg2
connection = self.get_connection()
with connection.cursor() as cursor:
try:
if not fake and statements.strip():
cursor.execute(statements)
except (
psycopg2.OperationalError,
psycopg2.ProgrammingError) as e:
connection.rollback()
print(e.message)
from sqlibrist.helpers import ApplyMigrationFailed
raise ApplyMigrationFailed
else:
cursor.execute('INSERT INTO sqlibrist.migrations '
'(migration) VALUES (%s);',
[name.split('/')[-1]])
connection.commit()
评论列表
文章目录