Skip to content

Commit

Permalink
Change __chrononaut_disable_indices__ to accept lists of columns
Browse files Browse the repository at this point in the history
  • Loading branch information
polyatail committed Jan 23, 2019
1 parent b634fc5 commit aa73c61
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion chrononaut/history_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _col_copy(col):
# we don't create copies of these columns on the version table b/c we don't save them anyways
untracked_cols = set(getattr(cls, '__chrononaut_untracked__', []))
hidden_cols = set(getattr(cls, '__chrononaut_hidden__', []))
noindex_cols = set(getattr(cls, '__chrononaut_disable_indices__', []))

properties = util.OrderedDict()
if not super_mapper or local_mapper.local_table is not super_mapper.local_table:
Expand All @@ -75,7 +76,7 @@ def _col_copy(col):
col = _col_copy(column)

# disable user-specified column indices on history tables, if indicated
if col.index is True and getattr(cls, '__chrononaut_disable_indices__', False):
if col.index is True and column.key in noindex_cols:
col.index = None

if super_mapper and col_references_table(column, super_mapper.local_table):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Todo(db.Model, chrononaut.Versioned):
__tablename__ = 'todos'
__chrononaut_hidden__ = ['done']
__chrononaut_untracked__ = ['starred']
__chrononaut_disable_indices__ = True
__chrononaut_disable_indices__ = ['pub_date']
id = db.Column('id', db.Integer, primary_key=True) # FIXME: `todo_id` fails as a col name
title = db.Column(db.String(60))
text = db.Column(db.Text)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_validation_transfer(db, session):

def test_index_transfer(db):
# Check that indices were not transferred to history table
assert db.Todo.__chrononaut_disable_indices__ is True
assert db.Todo.__chrononaut_disable_indices__ == ['pub_date']
assert db.Todo.pub_date.index is True
assert db.Todo.__history_mapper__.columns.pub_date.index is None

Expand Down

0 comments on commit aa73c61

Please sign in to comment.