Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
hkage committed Apr 16, 2021
2 parents 40800e0 + f181cb5 commit 9e7a921
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Development

## 0.3.3 (2021-04-16)

* [#16](https://github.com/rheinwerk-verlag/postgresql-anonymizer/issues/16): Preserve column and table cases during the copy process

## 0.3.2 (2021-01-25)

* [#15](https://github.com/rheinwerk-verlag/postgresql-anonymizer/pull/15): Fix for exclude bug ([abhinavvaidya90](https://github.com/abhinavvaidya90))
Expand Down
15 changes: 8 additions & 7 deletions pganonymizer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def build_data(connection, table, columns, excludes, total_count, verbose=False)
row[key] = value
if verbose:
progress_bar.next()
table_columns = row.keys()
table_columns = ['"{}"'.format(column) for column in row.keys()]
if not row_column_dict:
continue
data.append(row.values())
Expand Down Expand Up @@ -135,18 +135,19 @@ def import_data(connection, column_dict, source_table, table_columns, primary_ke
:param list data: The table data.
"""
primary_key = primary_key if primary_key else DEFAULT_PRIMARY_KEY
temp_table = '"tmp_{table}"'.format(table=source_table)
cursor = connection.cursor()
cursor.execute('CREATE TEMP TABLE source(LIKE %s INCLUDING ALL) ON COMMIT DROP;' % source_table)
copy_from(connection, data, 'source', table_columns)
set_columns = ', '.join(['{column} = s.{column}'.format(column=key) for key in column_dict.keys()])
cursor.execute('CREATE TEMP TABLE %s (LIKE %s INCLUDING ALL) ON COMMIT DROP;' % (temp_table, source_table))
copy_from(connection, data, temp_table, table_columns)
set_columns = ', '.join(['{column} = s.{column}'.format(column='"{}"'.format(key)) for key in column_dict.keys()])
sql = (
'UPDATE {table} t '
'SET {columns} '
'FROM source s '
'FROM {source} s '
'WHERE t.{primary_key} = s.{primary_key};'
).format(table=source_table, primary_key=primary_key, columns=set_columns)
).format(table=source_table, columns=set_columns, source=temp_table, primary_key=primary_key)
cursor.execute(sql)
cursor.execute('DROP TABLE source;')
cursor.execute('DROP TABLE %s;' % temp_table)
cursor.close()


Expand Down
2 changes: 1 addition & 1 deletion pganonymizer/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = '0.3.2'
__version__ = '0.3.3'

0 comments on commit 9e7a921

Please sign in to comment.