Fix has_index, fixes #148
- Make has_index work with tables without primary keys
This commit is contained in:
@@ -4,6 +4,12 @@ Changelog
|
|||||||
Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
||||||
|
|
||||||
|
|
||||||
|
0.30.8 (2015-06-xx)
|
||||||
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
- Make has_index work with tables without primary keys (#148)
|
||||||
|
|
||||||
|
|
||||||
0.30.7 (2015-05-28)
|
0.30.7 (2015-05-28)
|
||||||
^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@@ -247,8 +247,9 @@ def has_index(column):
|
|||||||
'Only columns belonging to Table objects are supported. Given '
|
'Only columns belonging to Table objects are supported. Given '
|
||||||
'column belongs to %r.' % table
|
'column belongs to %r.' % table
|
||||||
)
|
)
|
||||||
|
primary_keys = table.primary_key.columns.values()
|
||||||
return (
|
return (
|
||||||
column is table.primary_key.columns.values()[0]
|
(primary_keys and column is primary_keys[0])
|
||||||
or
|
or
|
||||||
any(
|
any(
|
||||||
index.columns.values()[0] is column
|
index.columns.values()[0] is column
|
||||||
|
@@ -39,3 +39,14 @@ class TestHasIndex(object):
|
|||||||
def test_compound_column_index(self):
|
def test_compound_column_index(self):
|
||||||
assert has_index(self.table.c.is_deleted)
|
assert has_index(self.table.c.is_deleted)
|
||||||
assert not has_index(self.table.c.is_archived)
|
assert not has_index(self.table.c.is_archived)
|
||||||
|
|
||||||
|
def test_table_without_primary_key(self):
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
|
article = sa.Table(
|
||||||
|
'article',
|
||||||
|
sa.MetaData(),
|
||||||
|
sa.Column('name', sa.String)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert not has_index(article.c.name)
|
||||||
|
Reference in New Issue
Block a user