diff --git a/database/database_table.py b/database/database_table.py index d97bf5427ff6989bcdac01a72c09bc2ae43e493a..e5a083c4f62cfb0fa4acad0df2923407d924ef75 100644 --- a/database/database_table.py +++ b/database/database_table.py @@ -532,13 +532,13 @@ class DatabaseTable(Table): def transfer_data(self, connection, transfer_list): ''' - Receives a list of columns to be transfered. Transfered columns are backed up, - removed, added with new parameters and then repopulated. - transfer_list must be a list of dictionaries with the following fields: - name - the name of the original column; - new_name - name for the new column. If None is passed, original name is used; - new_type - type for the new column. If None is passed, original type is used. - ''' + Receives a list of columns to be transfered. Transfered columns are backed up, + removed, added with new parameters and then repopulated. + transfer_list must be a list of dictionaries with the following fields: + name - the name of the original column; + new_name - name for the new column. If None is passed, original name is used; + new_type - type for the new column. If None is passed, original type is used. + ''' if not transfer_list: return pk_columns = list(self.primary_key.columns) @@ -570,9 +570,10 @@ class DatabaseTable(Table): values = {} for item in transfer_list: - temp_columns = [column for column in ttable.columns if column.key == item['new_name']] - values[item['new_name']] = select(temp_columns).where(list(self.primary_key.columns) == temp_pk_columns) + values[item['new_name']] = ttable.columns.get(item['new_name']) base_update = update(self).values(**values) + for original_pk, temp_pk in zip(list(self.primary_key.columns), temp_pk_columns): + base_update = base_update.where(original_pk == temp_pk) connection.execute(base_update) diff --git a/requirements.txt b/requirements.txt index 4ed7cb99c7a9d4805755f1838cefdb35ecb14536..17b7dfaf6e76921c8e6d496e4608de64d1a193be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,7 @@ pytz==2017.2 simplegeneric==0.8.1 six==1.11.0 SQLAlchemy==1.2.19 -sqlalchemy-monetdb==1.0.0 +-e git://github.com/jvwinandy/sqlalchemy-monetdb.git@1.0.1#egg=sqlalchemy-monetdb traitlets==4.3.2 wcwidth==0.1.7 wrapt==1.10.10