]> rtime.felk.cvut.cz Git - linux-conf-perf.git/commitdiff
Add database initialisation check
authorKarel Kočí <cynerd@email.cz>
Wed, 22 Jul 2015 09:28:57 +0000 (11:28 +0200)
committerKarel Kočí <cynerd@email.cz>
Wed, 22 Jul 2015 09:28:57 +0000 (11:28 +0200)
On object creation, when connection to server is established, is now implemented check if database has all tables as it should have.

scripts/database.py
scripts/exceptions.py
scripts/initialize.py

index 18ed724b86cf40c9917294322d5d44176cae19ea..0c4abe95470f6b8bd25ee0c06748b923da08f559 100644 (file)
@@ -3,6 +3,7 @@ import postgresql
 import collections
 
 import utils
+import exceptions
 from conf import conf
 
 def __git_describe__():
@@ -28,6 +29,13 @@ class database:
                                host = conf.db_host,
                                port = conf.db_port
                                )
+               # check if tables are present
+               tables = ('toolsgit', 'configurations', 'measure')
+               for tab in tables:
+                       val = self.db.prepare("""SELECT COUNT(*) FROM pg_class
+                                                          WHERE relname = $1""")(tab)[0][0]
+                       if val < 1:
+                               raise exceptions.DatabaseUninitialized()
 
        def check_toolsgit(self):
                "Return id of toolsgit row. If missing, it is inserted"
index ec170bab928165a8b8e8d327a832b85c5c462739..730664aa61b536abd63a61498aba76f59ba2a2c9 100644 (file)
@@ -39,3 +39,7 @@ class ProcessFailed(Exception):
        def __str__(self):
                return "Process failed: " + str(self.process) + \
                        " with return code: " + str(self.returncode)
+
+class DatabaseUninitialized(Exception):
+       def __str__(self):
+               return "Database seems to be uninitialized."
index 51713203d073e878321a9c3ecf80840e63be40b8..d4470b8e77d0627ae690943a72e7715984906ecd 100755 (executable)
@@ -21,6 +21,8 @@ def all():
                solution.generate()
        except exceptions.NoSolution:
                pass
+       # check if database is initialized
+       database.database()
 
 def base():
        print('Initialize base...')