aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-07-22 11:28:57 +0200
committerKarel Kočí <cynerd@email.cz>2015-07-22 11:28:57 +0200
commite291e4e7c831f34238bbcda1c39659826f04191c (patch)
treeff3fb0dc730ffd9c5fef87a88d072a427c6ad033
parent17cb74bcb4583921abc32ddbe2991f27ae816707 (diff)
downloadlinux-conf-perf-e291e4e7c831f34238bbcda1c39659826f04191c.tar.gz
linux-conf-perf-e291e4e7c831f34238bbcda1c39659826f04191c.tar.bz2
linux-conf-perf-e291e4e7c831f34238bbcda1c39659826f04191c.zip
Add database initialisation check
On object creation, when connection to server is established, is now implemented check if database has all tables as it should have.
-rw-r--r--scripts/database.py8
-rw-r--r--scripts/exceptions.py4
-rwxr-xr-xscripts/initialize.py2
3 files changed, 14 insertions, 0 deletions
diff --git a/scripts/database.py b/scripts/database.py
index 18ed724..0c4abe9 100644
--- a/scripts/database.py
+++ b/scripts/database.py
@@ -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"
diff --git a/scripts/exceptions.py b/scripts/exceptions.py
index ec170ba..730664a 100644
--- a/scripts/exceptions.py
+++ b/scripts/exceptions.py
@@ -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."
diff --git a/scripts/initialize.py b/scripts/initialize.py
index 5171320..d4470b8 100755
--- a/scripts/initialize.py
+++ b/scripts/initialize.py
@@ -21,6 +21,8 @@ def all():
solution.generate()
except exceptions.NoSolution:
pass
+ # check if database is initialized
+ database.database()
def base():
print('Initialize base...')