diff getan/backend.py @ 501:f5e1a78173cb

Old databases can now be read in. Added comments.
author Magnus Schieder <mschieder@intevation.de>
date Tue, 18 Sep 2018 12:13:51 +0200
parents 199b3e3657aa
children fea767901dbc
line wrap: on
line diff
--- a/getan/backend.py	Mon Sep 17 20:41:28 2018 +0200
+++ b/getan/backend.py	Tue Sep 18 12:13:51 2018 +0200
@@ -54,6 +54,18 @@
 """
 ]
 
+CREATE_RECOVER = """
+CREATE TABLE IF NOT EXISTS recover(
+    id          INTEGER PRIMARY KEY,
+    project_id  INTEGER REFERENCES projects(id),
+    start_time  TIMESTAMP NOT NULL,
+    stop_time   TIMESTAMP NOT NULL,
+    description VARCHAR(256),
+
+    CHECK (strftime('%s', start_time) <= strftime('%s', stop_time))
+)
+"""
+
 LOAD_ACTIVE_PROJECTS = '''
 SELECT id, key, description, total
 FROM projects LEFT JOIN
@@ -258,9 +270,14 @@
             close(cur)
 
     def load_recover(self):
+        """If there is an entry in the recovery table, the entry is moved to
+        its project."""
         cor = None
         try:
             cur = self.con.cursor()
+            # Creates the recover table if it does not exist to make old
+            # databases compatible.
+            cur.execute(CREATE_RECOVER)
             cur.execute(LOAD_RECOVER)
             recover = cur.fetchone()
             if not recover:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)