Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Fix ibmdb2 index name handling
Browse files Browse the repository at this point in the history
The ibmdb2 code calls _index_identifier() when it handles index name. This
method only exists from sqlalchemy 0.6.5 to 0.7.*. Nova code change
https://review.openstack.org/#/c/153123/ attempts to drop a db constraint and
it fails to sync nova db with sqlalchemy 0.9.8 running against db2. Need to let
ibmdb2 code identify sqlalchemy version and call the correct method to handle
index name.

Closes-Bug: 1428477

Change-Id: Ie6333f9cea0209c1ea290356873a1a1bcf409bed
  • Loading branch information
zhaoqin-github committed Mar 16, 2015
1 parent 8a638ce commit e57ee4c
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions migrate/changeset/databases/ibmdb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,28 @@ def _rename_table(self, table):
self.append("RENAME TABLE %s " % self.preparer.format_table(table))

def visit_index(self, index):
old_name = self.preparer.quote(self._index_identifier(index.name),
index.quote)
new_name = self.preparer.quote(self._index_identifier(index.new_name),
index.quote)
if hasattr(self, '_index_identifier'):
# SA >= 0.6.5, < 0.8
old_name = self.preparer.quote(
self._index_identifier(index.name), index.quote)
new_name = self.preparer.quote(
self._index_identifier(index.new_name), index.quote)
else:
# SA >= 0.8
class NewName(object):
"""Map obj.name -> obj.new_name"""
def __init__(self, index):
self.name = index.new_name
self._obj = index

def __getattr__(self, attr):
if attr == 'name':
return getattr(self, attr)
return getattr(self._obj, attr)

old_name = self._prepared_index_name(index)
new_name = self._prepared_index_name(NewName(index))

self.append("RENAME INDEX %s TO %s" % (old_name, new_name))
self.execute()
self.append("COMMIT")
Expand Down Expand Up @@ -293,8 +311,14 @@ def _visit_constraint(self, constraint):
constraint.exclude_nulls = True
break
if getattr(constraint, 'exclude_nulls', None):
index_name = self.preparer.quote(
self._index_identifier(constraint.name), constraint.quote)
if hasattr(self, '_index_identifier'):
# SA >= 0.6.5, < 0.8
index_name = self.preparer.quote(
self._index_identifier(constraint.name),
constraint.quote)
else:
# SA >= 0.8
index_name = self._prepared_index_name(constraint)
sql = 'DROP INDEX %s ' % index_name
else:
sql = self.process(DropConstraint(constraint,
Expand Down

0 comments on commit e57ee4c

Please sign in to comment.