changeset 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 f751499d3f8d
children fea767901dbc
files getan/backend.py getan/states.py
diffstat 2 files changed, 19 insertions(+), 0 deletions(-) [+]
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:
--- a/getan/states.py	Mon Sep 17 20:41:28 2018 +0200
+++ b/getan/states.py	Tue Sep 18 12:13:51 2018 +0200
@@ -281,6 +281,8 @@
                                                  'running')
             self.controller.loop.draw_screen()
             self.sec = self.sec + 1
+            # The time is stored every minute to be able to restore them in
+            # case of a crash.
             if self.sec % 60 == 0:
                 self.controller.save_recovery_data()
         else:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)