Browse Source

Don't use deprecated / non-functional "force" parameter

The "force" parameter in SQLAlchemy IdentifierPreparer.quote()
has been a no-op since 0.9 in
031ef08078,
which was six years ago.   In SQLAlchemy 1.3 this parameter
will be removed entirely.   Bump requirements to 0.9 series
here and remove usage of the "force" flag.

Change-Id: I4492df2e7d2075fefbf13d6782de11f7d402f6b8
changes/35/631335/2
Mike Bayer 3 years ago
parent
commit
fe64667106
  1. 17
      migrate/changeset/ansisql.py
  2. 2
      migrate/changeset/databases/firebird.py
  3. 13
      migrate/changeset/databases/ibmdb2.py
  4. 3
      migrate/changeset/databases/mysql.py
  5. 2
      migrate/changeset/schema.py
  6. 11
      migrate/changeset/util.py
  7. 2
      requirements.txt

17
migrate/changeset/ansisql.py

@ -159,8 +159,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
def visit_table(self, table):
"""Rename a table. Other ops aren't supported."""
self.start_alter_table(table)
q = util.safe_quote(table)
self.append("RENAME TO %s" % self.preparer.quote(table.new_name, q))
self.append("RENAME TO %s" % self.preparer.quote(table.new_name))
self.execute()
def visit_index(self, index):
@ -170,19 +169,19 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
self.append("ALTER INDEX %s RENAME TO %s" % (
self.preparer.quote(
self._validate_identifier(
index.name, True), index.quote),
index.name, True)),
self.preparer.quote(
self._validate_identifier(
index.new_name, True), index.quote)))
index.new_name, True))))
elif hasattr(self, '_index_identifier'):
# SA >= 0.6.5, < 0.8
self.append("ALTER INDEX %s RENAME TO %s" % (
self.preparer.quote(
self._index_identifier(
index.name), index.quote),
index.name)),
self.preparer.quote(
self._index_identifier(
index.new_name), index.quote)))
index.new_name))))
else:
# SA >= 0.8
class NewName(object):
@ -229,8 +228,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
def start_alter_column(self, table, col_name):
"""Starts ALTER COLUMN"""
self.start_alter_table(table)
q = util.safe_quote(table)
self.append("ALTER COLUMN %s " % self.preparer.quote(col_name, q))
self.append("ALTER COLUMN %s " % self.preparer.quote(col_name))
def _visit_column_nullable(self, table, column, delta):
nullable = delta['nullable']
@ -253,8 +251,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
def _visit_column_name(self, table, column, delta):
self.start_alter_table(table)
q = util.safe_quote(table)
col_name = self.preparer.quote(delta.current_name, q)
col_name = self.preparer.quote(delta.current_name)
new_name = self.preparer.format_column(delta.result_column)
self.append('RENAME COLUMN %s TO %s' % (col_name, new_name))

2
migrate/changeset/databases/firebird.py

@ -61,7 +61,7 @@ class FBSchemaChanger(ansisql.ANSISchemaChanger):
def _visit_column_name(self, table, column, delta):
self.start_alter_table(table)
col_name = self.preparer.quote(delta.current_name, table.quote)
col_name = self.preparer.quote(delta.current_name)
new_name = self.preparer.format_column(delta.result_column)
self.append('ALTER COLUMN %s TO %s' % (col_name, new_name))

13
migrate/changeset/databases/ibmdb2.py

@ -108,8 +108,7 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger):
"""Rename a table; #38. Other ops aren't supported."""
self._rename_table(table)
q = util.safe_quote(table)
self.append("TO %s" % self.preparer.quote(table.new_name, q))
self.append("TO %s" % self.preparer.quote(table.new_name))
self.execute()
self.append("COMMIT")
self.execute()
@ -121,9 +120,9 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger):
if hasattr(self, '_index_identifier'):
# SA >= 0.6.5, < 0.8
old_name = self.preparer.quote(
self._index_identifier(index.name), index.quote)
self._index_identifier(index.name))
new_name = self.preparer.quote(
self._index_identifier(index.new_name), index.quote)
self._index_identifier(index.new_name))
else:
# SA >= 0.8
class NewName(object):
@ -148,11 +147,10 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger):
def _run_subvisit(self, delta, func, start_alter=True):
"""Runs visit method based on what needs to be changed on column"""
table = delta.table
q = util.safe_quote(table)
if start_alter:
self.start_alter_table(table)
ret = func(table,
self.preparer.quote(delta.current_name, q),
self.preparer.quote(delta.current_name),
delta)
self.execute()
self._reorg_table(self.preparer.format_table(delta.table))
@ -314,8 +312,7 @@ class IBMDBConstraintDropper(ansisql.ANSIConstraintDropper,
if hasattr(self, '_index_identifier'):
# SA >= 0.6.5, < 0.8
index_name = self.preparer.quote(
self._index_identifier(constraint.name),
constraint.quote)
self._index_identifier(constraint.name))
else:
# SA >= 0.8
index_name = self._prepared_index_name(constraint)

3
migrate/changeset/databases/mysql.py

@ -37,8 +37,7 @@ class MySQLSchemaChanger(MySQLSchemaGenerator, ansisql.ANSISchemaChanger):
first = primary_keys.pop(0)
if first.name == delta.current_name:
colspec += " AUTO_INCREMENT"
q = util.safe_quote(table)
old_col_name = self.preparer.quote(delta.current_name, q)
old_col_name = self.preparer.quote(delta.current_name)
self.start_alter_table(table)

2
migrate/changeset/schema.py

@ -650,12 +650,10 @@ populated with defaults
# TODO: this is fixed in 0.6
def copy_fixed(self, **kw):
"""Create a copy of this ``Column``, with all attributes."""
q = util.safe_quote(self)
return sqlalchemy.Column(self.name, self.type, self.default,
key=self.key,
primary_key=self.primary_key,
nullable=self.nullable,
quote=q,
index=self.index,
unique=self.unique,
onupdate=self.onupdate,

11
migrate/changeset/util.py

@ -1,16 +1,5 @@
from migrate.changeset import SQLA_10
"""
Safe quoting method
"""
def safe_quote(obj):
# this is the SQLA 0.9 approach
if hasattr(obj, 'name') and hasattr(obj.name, 'quote'):
return obj.name.quote
else:
return obj.quote
def fk_column_names(constraint):
if SQLA_10:

2
requirements.txt

@ -6,7 +6,7 @@ pbr>=1.8
# never put a cap on this, *ever*, sqla versions are handled via
# tox, and if SQLA is capped it will only make it so we aren't testing
# against all the versions we are compatible with.
SQLAlchemy>=0.7.8,!=0.9.5
SQLAlchemy>=0.9.6
decorator
six>=1.7.0
sqlparse

Loading…
Cancel
Save