Files
@ 7e5f8c12a3fc
Branch filter:
Location: kallithea/rhodecode/lib/dbmigrate/migrate/versioning/script/sql.py - annotation
7e5f8c12a3fc
1.7 KiB
text/x-python
First step in two-part process to rename directories to kallithea.
This first step is to change all references in the files where they refer
to the old directory name.
This first step is to change all references in the files where they refer
to the old directory name.
9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 7e5f8c12a3fc 7e5f8c12a3fc 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 6832ef664673 9753e0907827 9753e0907827 9bb609d164e4 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 9753e0907827 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import shutil
from kallithea.lib.dbmigrate.migrate.versioning.script import base
from kallithea.lib.dbmigrate.migrate.versioning.template import Template
log = logging.getLogger(__name__)
class SqlScript(base.BaseScript):
"""A file containing plain SQL statements."""
@classmethod
def create(cls, path, **opts):
"""Create an empty migration script at specified path
:returns: :class:`SqlScript instance <migrate.versioning.script.sql.SqlScript>`"""
cls.require_notfound(path)
src = Template(opts.pop('templates_path', None)).get_sql_script(theme=opts.pop('templates_theme', None))
shutil.copy(src, path)
return cls(path)
# TODO: why is step parameter even here?
def run(self, engine, step=None, executemany=True):
"""Runs SQL script through raw dbapi execute call"""
text = self.source()
# Don't rely on SA's autocommit here
# (SA uses .startswith to check if a commit is needed. What if script
# starts with a comment?)
conn = engine.connect()
try:
trans = conn.begin()
try:
# HACK: SQLite doesn't allow multiple statements through
# its execute() method, but it provides executescript() instead
dbapi = conn.engine.raw_connection()
if executemany and getattr(dbapi, 'executescript', None):
dbapi.executescript(text)
else:
conn.execute(text)
trans.commit()
except:
trans.rollback()
raise
finally:
conn.close()
|