From 1a1d9a68c391e6b2815a01dc6a3fdc6487ea4f8f Mon Sep 17 00:00:00 2001
From: root <ppc19@inf.ufpr.br>
Date: Thu, 27 May 2021 13:53:07 +0000
Subject: [PATCH] insert does not alter temporary tables anymore

---
 database/actions.py        | 4 +++-
 database/database_table.py | 7 ++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/database/actions.py b/database/actions.py
index a346f0d..1cf3bb5 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 b785db3..1c769db 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):
-- 
GitLab