summaryrefslogtreecommitdiff
path: root/lorrycontroller/statedb.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/statedb.py')
-rw-r--r--lorrycontroller/statedb.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py
index 7f537f3..27e6fae 100644
--- a/lorrycontroller/statedb.py
+++ b/lorrycontroller/statedb.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2014 Codethink Limited
+# Copyright (C) 2014-2016 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -80,6 +80,13 @@ class StateDB(object):
logging.debug('New connection is %r', self._conn)
if not existed:
self._initialise_tables()
+ else:
+ c = self._conn.cursor()
+ c.execute('PRAGMA table_info(troves)')
+ columns = (info[1] for info in c.fetchall())
+ if 'gitlab_token' not in columns:
+ c.execute('ALTER TABLE troves ADD COLUMN gitlab_token')
+ self._conn.commit()
def _initialise_tables(self):
logging.debug('Initialising tables in database')
@@ -106,7 +113,8 @@ class StateDB(object):
'ls_interval INT, '
'ls_last_run INT, '
'prefixmap TEXT, '
- 'ignore TEXT '
+ 'ignore TEXT, '
+ 'gitlab_token TEXT '
')')
# Table for all the known lorries (the "run queue").
@@ -215,7 +223,7 @@ class StateDB(object):
c.execute(
'SELECT protocol, username, password, lorry_interval, '
'lorry_timeout, ls_interval, ls_last_run, '
- 'prefixmap, ignore '
+ 'prefixmap, ignore, gitlab_token '
'FROM troves WHERE trovehost IS ?',
(trovehost,))
row = c.fetchone()
@@ -232,12 +240,13 @@ class StateDB(object):
'ls_last_run': row[6],
'prefixmap': row[7],
'ignore': row[8],
- }
+ 'gitlab_token': row[9]
+ }
def add_trove(self, trovehost=None, protocol=None, username=None,
password=None, lorry_interval=None,
lorry_timeout=None, ls_interval=None,
- prefixmap=None, ignore=None):
+ prefixmap=None, ignore=None, gitlab_token=None):
logging.debug(
'StateDB.add_trove(%r,%r,%r,%r,%r,%r) called',
trovehost, lorry_interval, lorry_timeout, ls_interval,
@@ -261,20 +270,20 @@ class StateDB(object):
'(trovehost, protocol, username, password, '
'lorry_interval, lorry_timeout, '
'ls_interval, ls_last_run, '
- 'prefixmap, ignore) '
- 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
+ 'prefixmap, ignore, gitlab_token) '
+ 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
(trovehost, protocol, username, password,
lorry_interval, lorry_timeout, ls_interval, 0,
- prefixmap, ignore))
+ prefixmap, ignore, gitlab_token))
else:
c = self.get_cursor()
c.execute(
'UPDATE troves '
'SET lorry_interval=?, lorry_timeout=?, ls_interval=?, '
- 'prefixmap=?, ignore=?, protocol=? '
+ 'prefixmap=?, ignore=?, protocol=?, gitlab_token=? '
'WHERE trovehost IS ?',
(lorry_interval, lorry_timeout, ls_interval, prefixmap,
- ignore, protocol, trovehost))
+ ignore, protocol, gitlab_token, trovehost))
def remove_trove(self, trovehost):
logging.debug('StateDB.remove_trove(%r) called', trovehost)