summaryrefslogtreecommitdiff
path: root/migrate
diff options
context:
space:
mode:
Diffstat (limited to 'migrate')
-rw-r--r--migrate/changeset/ansisql.py15
-rw-r--r--migrate/changeset/databases/__init__.py2
-rw-r--r--migrate/changeset/databases/oracle.py6
-rw-r--r--migrate/changeset/databases/visitor.py4
-rw-r--r--migrate/versioning/api.py8
-rw-r--r--migrate/versioning/base/__init__.py4
-rw-r--r--migrate/versioning/base/const.py9
-rw-r--r--migrate/versioning/base/logger.py2
-rw-r--r--migrate/versioning/pathed.py2
-rw-r--r--migrate/versioning/schema.py4
-rw-r--r--migrate/versioning/script/py.py2
-rw-r--r--migrate/versioning/shell.py19
-rw-r--r--migrate/versioning/template.py10
-rw-r--r--migrate/versioning/version.py3
14 files changed, 55 insertions, 35 deletions
diff --git a/migrate/changeset/ansisql.py b/migrate/changeset/ansisql.py
index f80c38a..39fb261 100644
--- a/migrate/changeset/ansisql.py
+++ b/migrate/changeset/ansisql.py
@@ -99,7 +99,8 @@ class ANSIColumnGenerator(AlterTableVisitor, SchemaGenerator):
unique=bool(column.index_name or column.index))
ix.create()
elif column.unique_name:
- constraint.UniqueConstraint(column, name=column.unique_name).create()
+ constraint.UniqueConstraint(column,
+ name=column.unique_name).create()
# SA bounds FK constraints to table, add manually
for fk in column.foreign_keys:
@@ -107,7 +108,8 @@ class ANSIColumnGenerator(AlterTableVisitor, SchemaGenerator):
# add primary key constraint if needed
if column.primary_key_name:
- cons = constraint.PrimaryKeyConstraint(column, name=column.primary_key_name)
+ cons = constraint.PrimaryKeyConstraint(column,
+ name=column.primary_key_name)
cons.create()
@@ -145,14 +147,17 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
def visit_table(self, table):
"""Rename a table. Other ops aren't supported."""
self.start_alter_table(table)
- self.append("RENAME TO %s" % self.preparer.quote(table.new_name, table.quote))
+ self.append("RENAME TO %s" % self.preparer.quote(table.new_name,
+ table.quote))
self.execute()
def visit_index(self, index):
"""Rename an index"""
self.append("ALTER INDEX %s RENAME TO %s" %
- (self.preparer.quote(self._validate_identifier(index.name, True), index.quote),
- self.preparer.quote(self._validate_identifier(index.new_name, True) , index.quote)))
+ (self.preparer.quote(self._validate_identifier(index.name,
+ True), index.quote),
+ self.preparer.quote(self._validate_identifier(index.new_name,
+ True), index.quote)))
self.execute()
def visit_column(self, column):
diff --git a/migrate/changeset/databases/__init__.py b/migrate/changeset/databases/__init__.py
index 4abc187..8546918 100644
--- a/migrate/changeset/databases/__init__.py
+++ b/migrate/changeset/databases/__init__.py
@@ -2,7 +2,7 @@
This module contains database dialect specific changeset
implementations.
"""
-__all__=[
+__all__ = [
'postgres',
'sqlite',
'mysql',
diff --git a/migrate/changeset/databases/oracle.py b/migrate/changeset/databases/oracle.py
index abdaad8..59e266e 100644
--- a/migrate/changeset/databases/oracle.py
+++ b/migrate/changeset/databases/oracle.py
@@ -42,16 +42,14 @@ class OracleSchemaChanger(OracleSchemaGenerator, ansisql.ANSISchemaChanger):
def _visit_column_change(self, table, col_name, delta):
if not hasattr(delta, 'result_column'):
- # Oracle needs the whole column definition, not just a
- # lone name/type
+ # Oracle needs the whole column definition, not just a lone name/type
raise exceptions.NotSupportedError(
"A column object is required to do this")
column = delta.result_column
# Oracle cannot drop a default once created, but it can set it
# to null. We'll do that if default=None
- # http://forums.oracle.com/forums/message.jspa?\
- # messageID=1273234#1273234
+ # http://forums.oracle.com/forums/message.jspa?messageID=1273234#1273234
dropdefault_hack = (column.server_default is None \
and 'server_default' in delta.keys())
# Oracle apparently doesn't like it when we say "not null" if
diff --git a/migrate/changeset/databases/visitor.py b/migrate/changeset/databases/visitor.py
index 2f282c7..8a084fb 100644
--- a/migrate/changeset/databases/visitor.py
+++ b/migrate/changeset/databases/visitor.py
@@ -8,7 +8,7 @@ from migrate.changeset.databases import sqlite, postgres, mysql, oracle
# Map SA dialects to the corresponding Migrate extensions
-dialects = {
+DIALECTS = {
sa.engine.default.DefaultDialect: ansisql.ANSIDialect,
sa.databases.sqlite.SQLiteDialect: sqlite.SQLiteDialect,
sa.databases.postgres.PGDialect: postgres.PGDialect,
@@ -43,7 +43,7 @@ def get_dialect_visitor(sa_dialect, name):
# map sa dialect to migrate dialect and return visitor
sa_dialect_cls = sa_dialect.__class__
- migrate_dialect_cls = dialects[sa_dialect_cls]
+ migrate_dialect_cls = DIALECTS[sa_dialect_cls]
visitor = getattr(migrate_dialect_cls, name)
# bind preparer
diff --git a/migrate/versioning/api.py b/migrate/versioning/api.py
index d72d14e..6e0da11 100644
--- a/migrate/versioning/api.py
+++ b/migrate/versioning/api.py
@@ -2,11 +2,13 @@
This module provides an external API to the versioning system.
.. versionchanged:: 0.4.5
- ``--preview_sql`` displays source file when using SQL scripts. If Python script is used,
- it runs the action with mocked engine and returns captured SQL statements.
+ ``--preview_sql`` displays source file when using SQL scripts.
+ If Python script is used, it runs the action with mocked engine and
+ returns captured SQL statements.
.. versionchanged:: 0.4.5
- Deprecated ``--echo`` parameter in favour of new :func:`migrate.versioning.util.construct_engine` behavior.
+ Deprecated ``--echo`` parameter in favour of new
+ :func:`migrate.versioning.util.construct_engine` behavior.
"""
# Dear migrate developers,
diff --git a/migrate/versioning/base/__init__.py b/migrate/versioning/base/__init__.py
index 1c803d9..4c3842a 100644
--- a/migrate/versioning/base/__init__.py
+++ b/migrate/versioning/base/__init__.py
@@ -1,5 +1,5 @@
"""Things that should be imported by all migrate packages"""
#__all__ = ['logging','log','databases','operations']
-from logger import logging,log
-from const import databases,operations
+from logger import logging, log
+from const import databases, operations
diff --git a/migrate/versioning/base/const.py b/migrate/versioning/base/const.py
index 21271dd..590f6c0 100644
--- a/migrate/versioning/base/const.py
+++ b/migrate/versioning/base/const.py
@@ -1,10 +1,11 @@
-__all__ = ['databases','operations']
+from sqlalchemy.util import OrderedDict
+
-#databases = ('sqlite','postgres','mysql','oracle','mssql','firebird')
-databases = ('sqlite','postgres','mysql','oracle','mssql')
+__all__ = ['databases', 'operations']
+
+databases = ('sqlite', 'postgres', 'mysql', 'oracle', 'mssql')
# Map operation names to function names
-from sqlalchemy.util import OrderedDict
operations = OrderedDict()
operations['upgrade'] = 'upgrade'
operations['downgrade'] = 'downgrade'
diff --git a/migrate/versioning/base/logger.py b/migrate/versioning/base/logger.py
index 9cd3e59..0f97d40 100644
--- a/migrate/versioning/base/logger.py
+++ b/migrate/versioning/base/logger.py
@@ -6,4 +6,4 @@ log=logging.getLogger('migrate.versioning')
log.setLevel(logging.WARNING)
log.addHandler(logging.StreamHandler())
-__all__=['log','logging']
+__all__ = ['log','logging']
diff --git a/migrate/versioning/pathed.py b/migrate/versioning/pathed.py
index 2355486..6174737 100644
--- a/migrate/versioning/pathed.py
+++ b/migrate/versioning/pathed.py
@@ -52,7 +52,7 @@ class Pathed(KeyedInstance):
#
# Treat directories like files...
if path[-1] == '/':
- path=path[:-1]
+ path = path[:-1]
ret = os.path.dirname(path)
return ret
diff --git a/migrate/versioning/schema.py b/migrate/versioning/schema.py
index 9b71ba7..5227ccc 100644
--- a/migrate/versioning/schema.py
+++ b/migrate/versioning/schema.py
@@ -62,7 +62,9 @@ class ControlledSchema(object):
def changeset(self, version=None):
"""API to Changeset creation.
- Uses self.version for start version and engine.name to get database name."""
+ Uses self.version for start version and engine.name
+ to get database name.
+ """
database = self.engine.name
start_ver = self.version
changeset = self.repository.changeset(database, start_ver, version)
diff --git a/migrate/versioning/script/py.py b/migrate/versioning/script/py.py
index c08d438..6a089ee 100644
--- a/migrate/versioning/script/py.py
+++ b/migrate/versioning/script/py.py
@@ -112,7 +112,7 @@ class PythonScript(base.BaseScript):
"""
buf = StringIO()
args['engine_arg_strategy'] = 'mock'
- args['engine_arg_executor'] = lambda s, p='': buf.write(s + p)
+ args['engine_arg_executor'] = lambda s, p = '': buf.write(s + p)
engine = construct_engine(url, **args)
self.run(engine, step)
diff --git a/migrate/versioning/shell.py b/migrate/versioning/shell.py
index 2489f6b..3fa1478 100644
--- a/migrate/versioning/shell.py
+++ b/migrate/versioning/shell.py
@@ -17,8 +17,8 @@ alias = dict(
def alias_setup():
global alias
- for key,val in alias.iteritems():
- setattr(api,key,val)
+ for key, val in alias.iteritems():
+ setattr(api, key, val)
alias_setup()
@@ -33,7 +33,8 @@ class PassiveOptionParser(OptionParser):
del rargs[0]
return
elif arg[0:2] == "--":
- # if parser does not know about the option, pass it along (make it anonymous)
+ # if parser does not know about the option
+ # pass it along (make it anonymous)
try:
opt = arg.split('=', 1)[0]
self._match_long_opt(opt)
@@ -49,13 +50,15 @@ class PassiveOptionParser(OptionParser):
del rargs[0]
def main(argv=None, **kwargs):
- """kwargs are default options that can be overriden with passing --some_option to cmdline"""
+ """kwargs are default options that can be overriden with passing
+ --some_option to cmdline
+ """
argv = argv or list(sys.argv[1:])
commands = list(api.__all__)
commands.sort()
- usage="""%%prog COMMAND ...
+ usage = """%%prog COMMAND ...
Available commands:
%s
@@ -129,7 +132,8 @@ def main(argv=None, **kwargs):
try:
kw = f_required.pop(0)
except IndexError:
- parser.error("Too many arguments for command %s: %s" % (command, arg))
+ parser.error("Too many arguments for command %s: %s" % (command,
+ arg))
kwargs[kw] = arg
# apply overrides
@@ -143,7 +147,8 @@ def main(argv=None, **kwargs):
f_args_default = f_args[len(f_args) - num_defaults:]
required = list(set(f_required) - set(f_args_default))
if required:
- parser.error("Not enough arguments for command %s: %s not specified" % (command, ', '.join(required)))
+ parser.error("Not enough arguments for command %s: %s not specified" \
+ % (command, ', '.join(required)))
# handle command
try:
diff --git a/migrate/versioning/template.py b/migrate/versioning/template.py
index f20d391..91606a7 100644
--- a/migrate/versioning/template.py
+++ b/migrate/versioning/template.py
@@ -24,6 +24,7 @@ class Packaged(pathed.Pathed):
ret = resource_filename(pkg_name, resource_name)
return ret
+
class Collection(Packaged):
"""A collection of templates of a specific type"""
@@ -35,12 +36,15 @@ class Collection(Packaged):
def get_pkg(self, file):
return (self.pkg, str(file))
+
class RepositoryCollection(Collection):
_default = 'default'
+
class ScriptCollection(Collection):
_default = 'default.py_tmpl'
+
class Template(Packaged):
"""Finds the paths/packages of various Migrate templates"""
@@ -50,8 +54,9 @@ class Template(Packaged):
def __init__(self, pkg):
super(Template, self).__init__(pkg)
- self.repository=RepositoryCollection('.'.join((self.pkg, self._repository)))
- self.script=ScriptCollection('.'.join((self.pkg, self._script)))
+ self.repository = RepositoryCollection('.'.join((self.pkg,
+ self._repository)))
+ self.script = ScriptCollection('.'.join((self.pkg, self._script)))
def get_item(self, attr, filename=None, as_pkg=None, as_str=None):
item = getattr(self, attr)
@@ -74,5 +79,6 @@ class Template(Packaged):
def manage(self, **k):
return (self.pkg, self._manage)
+
template_pkg = 'migrate.versioning.templates'
template = Template(template_pkg)
diff --git a/migrate/versioning/version.py b/migrate/versioning/version.py
index ab457ab..18dc00a 100644
--- a/migrate/versioning/version.py
+++ b/migrate/versioning/version.py
@@ -161,7 +161,8 @@ class Version(object):
# TODO: maybe add force Python parameter?
ret = self.python
- assert ret is not None, "There is no script for %d version" % self.version
+ assert ret is not None,
+ "There is no script for %d version" % self.version
return ret
# deprecated?