some more PEP8 love
This commit is contained in:
parent
4b50def6ea
commit
672d9bd576
@ -99,7 +99,8 @@ class ANSIColumnGenerator(AlterTableVisitor, SchemaGenerator):
|
|||||||
unique=bool(column.index_name or column.index))
|
unique=bool(column.index_name or column.index))
|
||||||
ix.create()
|
ix.create()
|
||||||
elif column.unique_name:
|
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
|
# SA bounds FK constraints to table, add manually
|
||||||
for fk in column.foreign_keys:
|
for fk in column.foreign_keys:
|
||||||
@ -107,7 +108,8 @@ class ANSIColumnGenerator(AlterTableVisitor, SchemaGenerator):
|
|||||||
|
|
||||||
# add primary key constraint if needed
|
# add primary key constraint if needed
|
||||||
if column.primary_key_name:
|
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()
|
cons.create()
|
||||||
|
|
||||||
|
|
||||||
@ -145,14 +147,17 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
|
|||||||
def visit_table(self, table):
|
def visit_table(self, table):
|
||||||
"""Rename a table. Other ops aren't supported."""
|
"""Rename a table. Other ops aren't supported."""
|
||||||
self.start_alter_table(table)
|
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()
|
self.execute()
|
||||||
|
|
||||||
def visit_index(self, index):
|
def visit_index(self, index):
|
||||||
"""Rename an index"""
|
"""Rename an index"""
|
||||||
self.append("ALTER INDEX %s RENAME TO %s" %
|
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.name,
|
||||||
self.preparer.quote(self._validate_identifier(index.new_name, True) , index.quote)))
|
True), index.quote),
|
||||||
|
self.preparer.quote(self._validate_identifier(index.new_name,
|
||||||
|
True), index.quote)))
|
||||||
self.execute()
|
self.execute()
|
||||||
|
|
||||||
def visit_column(self, column):
|
def visit_column(self, column):
|
||||||
|
@ -42,16 +42,14 @@ class OracleSchemaChanger(OracleSchemaGenerator, ansisql.ANSISchemaChanger):
|
|||||||
|
|
||||||
def _visit_column_change(self, table, col_name, delta):
|
def _visit_column_change(self, table, col_name, delta):
|
||||||
if not hasattr(delta, 'result_column'):
|
if not hasattr(delta, 'result_column'):
|
||||||
# Oracle needs the whole column definition, not just a
|
# Oracle needs the whole column definition, not just a lone name/type
|
||||||
# lone name/type
|
|
||||||
raise exceptions.NotSupportedError(
|
raise exceptions.NotSupportedError(
|
||||||
"A column object is required to do this")
|
"A column object is required to do this")
|
||||||
|
|
||||||
column = delta.result_column
|
column = delta.result_column
|
||||||
# Oracle cannot drop a default once created, but it can set it
|
# Oracle cannot drop a default once created, but it can set it
|
||||||
# to null. We'll do that if default=None
|
# to null. We'll do that if default=None
|
||||||
# http://forums.oracle.com/forums/message.jspa?\
|
# http://forums.oracle.com/forums/message.jspa?messageID=1273234#1273234
|
||||||
# messageID=1273234#1273234
|
|
||||||
dropdefault_hack = (column.server_default is None \
|
dropdefault_hack = (column.server_default is None \
|
||||||
and 'server_default' in delta.keys())
|
and 'server_default' in delta.keys())
|
||||||
# Oracle apparently doesn't like it when we say "not null" if
|
# Oracle apparently doesn't like it when we say "not null" if
|
||||||
|
@ -8,7 +8,7 @@ from migrate.changeset.databases import sqlite, postgres, mysql, oracle
|
|||||||
|
|
||||||
|
|
||||||
# Map SA dialects to the corresponding Migrate extensions
|
# Map SA dialects to the corresponding Migrate extensions
|
||||||
dialects = {
|
DIALECTS = {
|
||||||
sa.engine.default.DefaultDialect: ansisql.ANSIDialect,
|
sa.engine.default.DefaultDialect: ansisql.ANSIDialect,
|
||||||
sa.databases.sqlite.SQLiteDialect: sqlite.SQLiteDialect,
|
sa.databases.sqlite.SQLiteDialect: sqlite.SQLiteDialect,
|
||||||
sa.databases.postgres.PGDialect: postgres.PGDialect,
|
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
|
# map sa dialect to migrate dialect and return visitor
|
||||||
sa_dialect_cls = sa_dialect.__class__
|
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)
|
visitor = getattr(migrate_dialect_cls, name)
|
||||||
|
|
||||||
# bind preparer
|
# bind preparer
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
This module provides an external API to the versioning system.
|
This module provides an external API to the versioning system.
|
||||||
|
|
||||||
.. versionchanged:: 0.4.5
|
.. versionchanged:: 0.4.5
|
||||||
``--preview_sql`` displays source file when using SQL scripts. If Python script is used,
|
``--preview_sql`` displays source file when using SQL scripts.
|
||||||
it runs the action with mocked engine and returns captured SQL statements.
|
If Python script is used, it runs the action with mocked engine and
|
||||||
|
returns captured SQL statements.
|
||||||
|
|
||||||
.. versionchanged:: 0.4.5
|
.. 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,
|
# Dear migrate developers,
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
from sqlalchemy.util import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['databases', 'operations']
|
__all__ = ['databases', 'operations']
|
||||||
|
|
||||||
#databases = ('sqlite','postgres','mysql','oracle','mssql','firebird')
|
|
||||||
databases = ('sqlite', 'postgres', 'mysql', 'oracle', 'mssql')
|
databases = ('sqlite', 'postgres', 'mysql', 'oracle', 'mssql')
|
||||||
|
|
||||||
# Map operation names to function names
|
# Map operation names to function names
|
||||||
from sqlalchemy.util import OrderedDict
|
|
||||||
operations = OrderedDict()
|
operations = OrderedDict()
|
||||||
operations['upgrade'] = 'upgrade'
|
operations['upgrade'] = 'upgrade'
|
||||||
operations['downgrade'] = 'downgrade'
|
operations['downgrade'] = 'downgrade'
|
||||||
|
@ -62,7 +62,9 @@ class ControlledSchema(object):
|
|||||||
def changeset(self, version=None):
|
def changeset(self, version=None):
|
||||||
"""API to Changeset creation.
|
"""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
|
database = self.engine.name
|
||||||
start_ver = self.version
|
start_ver = self.version
|
||||||
changeset = self.repository.changeset(database, start_ver, version)
|
changeset = self.repository.changeset(database, start_ver, version)
|
||||||
|
@ -33,7 +33,8 @@ class PassiveOptionParser(OptionParser):
|
|||||||
del rargs[0]
|
del rargs[0]
|
||||||
return
|
return
|
||||||
elif arg[0:2] == "--":
|
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:
|
try:
|
||||||
opt = arg.split('=', 1)[0]
|
opt = arg.split('=', 1)[0]
|
||||||
self._match_long_opt(opt)
|
self._match_long_opt(opt)
|
||||||
@ -49,7 +50,9 @@ class PassiveOptionParser(OptionParser):
|
|||||||
del rargs[0]
|
del rargs[0]
|
||||||
|
|
||||||
def main(argv=None, **kwargs):
|
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:])
|
argv = argv or list(sys.argv[1:])
|
||||||
commands = list(api.__all__)
|
commands = list(api.__all__)
|
||||||
@ -129,7 +132,8 @@ def main(argv=None, **kwargs):
|
|||||||
try:
|
try:
|
||||||
kw = f_required.pop(0)
|
kw = f_required.pop(0)
|
||||||
except IndexError:
|
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
|
kwargs[kw] = arg
|
||||||
|
|
||||||
# apply overrides
|
# apply overrides
|
||||||
@ -143,7 +147,8 @@ def main(argv=None, **kwargs):
|
|||||||
f_args_default = f_args[len(f_args) - num_defaults:]
|
f_args_default = f_args[len(f_args) - num_defaults:]
|
||||||
required = list(set(f_required) - set(f_args_default))
|
required = list(set(f_required) - set(f_args_default))
|
||||||
if required:
|
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
|
# handle command
|
||||||
try:
|
try:
|
||||||
|
@ -24,6 +24,7 @@ class Packaged(pathed.Pathed):
|
|||||||
ret = resource_filename(pkg_name, resource_name)
|
ret = resource_filename(pkg_name, resource_name)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class Collection(Packaged):
|
class Collection(Packaged):
|
||||||
"""A collection of templates of a specific type"""
|
"""A collection of templates of a specific type"""
|
||||||
|
|
||||||
@ -35,12 +36,15 @@ class Collection(Packaged):
|
|||||||
def get_pkg(self, file):
|
def get_pkg(self, file):
|
||||||
return (self.pkg, str(file))
|
return (self.pkg, str(file))
|
||||||
|
|
||||||
|
|
||||||
class RepositoryCollection(Collection):
|
class RepositoryCollection(Collection):
|
||||||
_default = 'default'
|
_default = 'default'
|
||||||
|
|
||||||
|
|
||||||
class ScriptCollection(Collection):
|
class ScriptCollection(Collection):
|
||||||
_default = 'default.py_tmpl'
|
_default = 'default.py_tmpl'
|
||||||
|
|
||||||
|
|
||||||
class Template(Packaged):
|
class Template(Packaged):
|
||||||
"""Finds the paths/packages of various Migrate templates"""
|
"""Finds the paths/packages of various Migrate templates"""
|
||||||
|
|
||||||
@ -50,7 +54,8 @@ class Template(Packaged):
|
|||||||
|
|
||||||
def __init__(self, pkg):
|
def __init__(self, pkg):
|
||||||
super(Template, self).__init__(pkg)
|
super(Template, self).__init__(pkg)
|
||||||
self.repository=RepositoryCollection('.'.join((self.pkg, self._repository)))
|
self.repository = RepositoryCollection('.'.join((self.pkg,
|
||||||
|
self._repository)))
|
||||||
self.script = ScriptCollection('.'.join((self.pkg, self._script)))
|
self.script = ScriptCollection('.'.join((self.pkg, self._script)))
|
||||||
|
|
||||||
def get_item(self, attr, filename=None, as_pkg=None, as_str=None):
|
def get_item(self, attr, filename=None, as_pkg=None, as_str=None):
|
||||||
@ -74,5 +79,6 @@ class Template(Packaged):
|
|||||||
def manage(self, **k):
|
def manage(self, **k):
|
||||||
return (self.pkg, self._manage)
|
return (self.pkg, self._manage)
|
||||||
|
|
||||||
|
|
||||||
template_pkg = 'migrate.versioning.templates'
|
template_pkg = 'migrate.versioning.templates'
|
||||||
template = Template(template_pkg)
|
template = Template(template_pkg)
|
||||||
|
@ -161,7 +161,8 @@ class Version(object):
|
|||||||
# TODO: maybe add force Python parameter?
|
# TODO: maybe add force Python parameter?
|
||||||
ret = self.python
|
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
|
return ret
|
||||||
|
|
||||||
# deprecated?
|
# deprecated?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user