diff --git a/database/actions.py b/database/actions.py index a346f0da38e13d5f0045a55adcda610dc8e417e2..cb83c298508a8b378d4adb2880f1e7cf7936bc42 100644 --- a/database/actions.py +++ b/database/actions.py @@ -51,7 +51,8 @@ def temporary_data(connection, file_name, table, year, offset=2, ttable.create(bind=connection) table.populate_temporary(ttable, file_name, header, year, delimiters, null, offset, bind=connection) - table.apply_derivatives(ttable, ttable.columns.keys(), year, bind=connection) + if len(table._derivatives) != 0: + table.apply_derivatives(ttable, ttable.columns.keys(), year, bind=connection) table.add_pk_to_temporary(ttable, bind=connection) return ttable @@ -68,6 +69,7 @@ def insert(file_name, table, year, offset=2, delimiters=[';', '\\n', '"'], null= ttable = temporary_data(connection, file_name, table, year, offset, delimiters, null) table.insert_from_temporary(ttable, bind=connection) + ttable.drop() trans.commit() @@ -122,6 +124,7 @@ def update_from_file(file_name, table, year, columns=None, ttable = temporary_data(connection, file_name, table, year, offset, delimiters, null) table.update_from_temporary(ttable, columns, bind=connection) + ttable.drop() trans.commit() diff --git a/database/database_table.py b/database/database_table.py index 5ada6e8bac6fd58742067a2c601bc3981435474e..1ac5d0c6ffb54480cb29630f1319e5ecec1f5433 100644 --- a/database/database_table.py +++ b/database/database_table.py @@ -181,7 +181,7 @@ class DatabaseTable(Table): logger.info("Acquiring temporary table with name '%s'", name) logger.debug("Temporary table '%s' with list of extra columns %s", name, header_columns) - ttable = Table(name, self.metadata, prefixes=['TEMPORARY'], schema='tmp') + ttable = Table(name, self.metadata, schema='sys') for target in self._protocol.get_targets(): try: @@ -610,7 +610,7 @@ class DatabaseTable(Table): trans = connection.begin() ttable = Table('t_' + self.name, self.metadata, *(temp_pk_columns + temp_columns), - schema="tmp", prefixes=["TEMPORARY"]) + schema="sys") ttable.create(bind=connection) ttable.schema = None @@ -990,7 +990,8 @@ class DatabaseTable(Table): # Run derivatives ttable = self.create_temporary_mirror(year, bind) - self.apply_derivatives(ttable, ttable.columns.keys(), year, bind, dbonly=True) + if len(ttable._derivatives) != 0: + self.apply_derivatives(ttable, ttable.columns.keys(), year, bind, dbonly=True) self.update_from_temporary(ttable, ttable.columns.keys(), bind) def get_relations(self, table):