Commit fe646671 authored by Mike Bayer's avatar Mike Bayer

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

The "force" parameter in SQLAlchemy IdentifierPreparer.quote()
has been a no-op since 0.9 in
https://github.com/sqlalchemy/sqlalchemy/commit/031ef0807838842a827135dbace760da7aec215e,
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
parent 8fd7226f
...@@ -159,8 +159,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator): ...@@ -159,8 +159,7 @@ 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)
q = util.safe_quote(table) self.append("RENAME TO %s" % self.preparer.quote(table.new_name))
self.append("RENAME TO %s" % self.preparer.quote(table.new_name, q))
self.execute() self.execute()
def visit_index(self, index): def visit_index(self, index):
...@@ -170,19 +169,19 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator): ...@@ -170,19 +169,19 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
self.append("ALTER INDEX %s RENAME TO %s" % ( self.append("ALTER INDEX %s RENAME TO %s" % (
self.preparer.quote( self.preparer.quote(
self._validate_identifier( self._validate_identifier(
index.name, True), index.quote), index.name, True)),
self.preparer.quote( self.preparer.quote(
self._validate_identifier( self._validate_identifier(
index.new_name, True), index.quote))) index.new_name, True))))
elif hasattr(self, '_index_identifier'): elif hasattr(self, '_index_identifier'):
# SA >= 0.6.5, < 0.8 # SA >= 0.6.5, < 0.8
self.append("ALTER INDEX %s RENAME TO %s" % ( self.append("ALTER INDEX %s RENAME TO %s" % (
self.preparer.quote( self.preparer.quote(
self._index_identifier( self._index_identifier(
index.name), index.quote), index.name)),
self.preparer.quote( self.preparer.quote(
self._index_identifier( self._index_identifier(
index.new_name), index.quote))) index.new_name))))
else: else:
# SA >= 0.8 # SA >= 0.8
class NewName(object): class NewName(object):
...@@ -229,8 +228,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator): ...@@ -229,8 +228,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
def start_alter_column(self, table, col_name): def start_alter_column(self, table, col_name):
"""Starts ALTER COLUMN""" """Starts ALTER COLUMN"""
self.start_alter_table(table) self.start_alter_table(table)
q = util.safe_quote(table) self.append("ALTER COLUMN %s " % self.preparer.quote(col_name))
self.append("ALTER COLUMN %s " % self.preparer.quote(col_name, q))
def _visit_column_nullable(self, table, column, delta): def _visit_column_nullable(self, table, column, delta):
nullable = delta['nullable'] nullable = delta['nullable']
...@@ -253,8 +251,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator): ...@@ -253,8 +251,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
def _visit_column_name(self, table, column, delta): def _visit_column_name(self, table, column, delta):
self.start_alter_table(table) self.start_alter_table(table)
q = util.safe_quote(table) col_name = self.preparer.quote(delta.current_name)
col_name = self.preparer.quote(delta.current_name, q)
new_name = self.preparer.format_column(delta.result_column) new_name = self.preparer.format_column(delta.result_column)
self.append('RENAME COLUMN %s TO %s' % (col_name, new_name)) self.append('RENAME COLUMN %s TO %s' % (col_name, new_name))
......
...@@ -61,7 +61,7 @@ class FBSchemaChanger(ansisql.ANSISchemaChanger): ...@@ -61,7 +61,7 @@ class FBSchemaChanger(ansisql.ANSISchemaChanger):
def _visit_column_name(self, table, column, delta): def _visit_column_name(self, table, column, delta):
self.start_alter_table(table) 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) new_name = self.preparer.format_column(delta.result_column)
self.append('ALTER COLUMN %s TO %s' % (col_name, new_name)) self.append('ALTER COLUMN %s TO %s' % (col_name, new_name))
......
...@@ -108,8 +108,7 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger): ...@@ -108,8 +108,7 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger):
"""Rename a table; #38. Other ops aren't supported.""" """Rename a table; #38. Other ops aren't supported."""
self._rename_table(table) self._rename_table(table)
q = util.safe_quote(table) self.append("TO %s" % self.preparer.quote(table.new_name))
self.append("TO %s" % self.preparer.quote(table.new_name, q))
self.execute() self.execute()
self.append("COMMIT") self.append("COMMIT")
self.execute() self.execute()
...@@ -121,9 +120,9 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger): ...@@ -121,9 +120,9 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger):
if hasattr(self, '_index_identifier'): if hasattr(self, '_index_identifier'):
# SA >= 0.6.5, < 0.8 # SA >= 0.6.5, < 0.8
old_name = self.preparer.quote( old_name = self.preparer.quote(
self._index_identifier(index.name), index.quote) self._index_identifier(index.name))
new_name = self.preparer.quote( new_name = self.preparer.quote(
self._index_identifier(index.new_name), index.quote) self._index_identifier(index.new_name))
else: else:
# SA >= 0.8 # SA >= 0.8
class NewName(object): class NewName(object):
...@@ -148,11 +147,10 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger): ...@@ -148,11 +147,10 @@ class IBMDBSchemaChanger(IBMDBSchemaGenerator, ansisql.ANSISchemaChanger):
def _run_subvisit(self, delta, func, start_alter=True): def _run_subvisit(self, delta, func, start_alter=True):
"""Runs visit method based on what needs to be changed on column""" """Runs visit method based on what needs to be changed on column"""
table = delta.table table = delta.table
q = util.safe_quote(table)
if start_alter: if start_alter:
self.start_alter_table(table) self.start_alter_table(table)
ret = func(table, ret = func(table,
self.preparer.quote(delta.current_name, q), self.preparer.quote(delta.current_name),
delta) delta)
self.execute() self.execute()
self._reorg_table(self.preparer.format_table(delta.table)) self._reorg_table(self.preparer.format_table(delta.table))
...@@ -314,8 +312,7 @@ class IBMDBConstraintDropper(ansisql.ANSIConstraintDropper, ...@@ -314,8 +312,7 @@ class IBMDBConstraintDropper(ansisql.ANSIConstraintDropper,
if hasattr(self, '_index_identifier'): if hasattr(self, '_index_identifier'):
# SA >= 0.6.5, < 0.8 # SA >= 0.6.5, < 0.8
index_name = self.preparer.quote( index_name = self.preparer.quote(
self._index_identifier(constraint.name), self._index_identifier(constraint.name))
constraint.quote)
else: else:
# SA >= 0.8 # SA >= 0.8
index_name = self._prepared_index_name(constraint) index_name = self._prepared_index_name(constraint)
......
...@@ -37,8 +37,7 @@ class MySQLSchemaChanger(MySQLSchemaGenerator, ansisql.ANSISchemaChanger): ...@@ -37,8 +37,7 @@ class MySQLSchemaChanger(MySQLSchemaGenerator, ansisql.ANSISchemaChanger):
first = primary_keys.pop(0) first = primary_keys.pop(0)
if first.name == delta.current_name: if first.name == delta.current_name:
colspec += " AUTO_INCREMENT" colspec += " AUTO_INCREMENT"
q = util.safe_quote(table) old_col_name = self.preparer.quote(delta.current_name)
old_col_name = self.preparer.quote(delta.current_name, q)
self.start_alter_table(table) self.start_alter_table(table)
......
...@@ -650,12 +650,10 @@ populated with defaults ...@@ -650,12 +650,10 @@ populated with defaults
# TODO: this is fixed in 0.6 # TODO: this is fixed in 0.6
def copy_fixed(self, **kw): def copy_fixed(self, **kw):
"""Create a copy of this ``Column``, with all attributes.""" """Create a copy of this ``Column``, with all attributes."""
q = util.safe_quote(self)
return sqlalchemy.Column(self.name, self.type, self.default, return sqlalchemy.Column(self.name, self.type, self.default,
key=self.key, key=self.key,
primary_key=self.primary_key, primary_key=self.primary_key,
nullable=self.nullable, nullable=self.nullable,
quote=q,
index=self.index, index=self.index,
unique=self.unique, unique=self.unique,
onupdate=self.onupdate, onupdate=self.onupdate,
......
from migrate.changeset import SQLA_10 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): def fk_column_names(constraint):
if SQLA_10: if SQLA_10:
......
...@@ -6,7 +6,7 @@ pbr>=1.8 ...@@ -6,7 +6,7 @@ pbr>=1.8
# never put a cap on this, *ever*, sqla versions are handled via # 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 # tox, and if SQLA is capped it will only make it so we aren't testing
# against all the versions we are compatible with. # against all the versions we are compatible with.
SQLAlchemy>=0.7.8,!=0.9.5 SQLAlchemy>=0.9.6
decorator decorator
six>=1.7.0 six>=1.7.0
sqlparse sqlparse
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment