diff --git a/database/actions.py b/database/actions.py index a346f0da38e13d5f0045a55adcda610dc8e417e2..1cf3bb52af8d8a0334bc7659021ca15afe3b4f65 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() diff --git a/database/database_table.py b/database/database_table.py index b785db32c1ec698bebf9aa7899bb17de0068cab9..1c769dbc90fcf5d58cb93dd4dad95a251abfb4d2 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 @@ -979,7 +979,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):