summaryrefslogtreecommitdiff
path: root/lorrycontroller/statedb.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/statedb.py')
-rw-r--r--lorrycontroller/statedb.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py
index 27e6fae..4b00db0 100644
--- a/lorrycontroller/statedb.py
+++ b/lorrycontroller/statedb.py
@@ -19,6 +19,8 @@ import os
import sqlite3
import time
+import yoyo
+
import lorrycontroller
@@ -80,13 +82,14 @@ 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()
+
+ self.perform_any_migrations()
+
+ def perform_any_migrations(self):
+ backend = yoyo.get_backend('sqlite:///' + self._filename)
+ migrations_dir = os.path.join(os.path.dirname(__file__), 'migrations')
+ migrations = yoyo.read_migrations(migrations_dir)
+ backend.apply_migrations(backend.to_apply(migrations))
def _initialise_tables(self):
logging.debug('Initialising tables in database')
@@ -113,8 +116,7 @@ class StateDB(object):
'ls_interval INT, '
'ls_last_run INT, '
'prefixmap TEXT, '
- 'ignore TEXT, '
- 'gitlab_token TEXT '
+ 'ignore TEXT '
')')
# Table for all the known lorries (the "run queue").