summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <ben.hutchings@codethink.co.uk>2020-05-06 22:14:00 +0100
committerBen Hutchings <ben.hutchings@codethink.co.uk>2020-06-01 15:26:47 +0100
commit5963f66a434d49a4a6e8dfc02cfe256c88d1e1e6 (patch)
tree77da19156fa89124a7a22a4e40cc60962ec7dbda
parent68cc92a192d1c48e8abad7615239f941059fca47 (diff)
downloadlorry-controller-5963f66a434d49a4a6e8dfc02cfe256c88d1e1e6.tar.gz
lorrycontroller.statedb: Allow internal keys and column names to diverge
I want to remove "trove" from internal APIs without having to immediately change the database schema. So we'll still have a column "from_trovehost" in the database schema but get_lorry_info should map that to "from_host".
-rw-r--r--lorrycontroller/statedb.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py
index b2bac7e..8659fc8 100644
--- a/lorrycontroller/statedb.py
+++ b/lorrycontroller/statedb.py
@@ -57,20 +57,20 @@ class StateDB(object):
self._transaction_started = None
self.initial_lorries_fields = [
- ('path', 'TEXT PRIMARY KEY'),
- ('text', 'TEXT'),
- ('from_trovehost', 'TEXT'),
- ('from_path', 'TEXT'),
- ('running_job', 'INT'),
- ('last_run', 'INT'),
- ('interval', 'INT'),
- ('lorry_timeout', 'INT'),
- ('disk_usage', 'INT'),
+ ('path', 'TEXT PRIMARY KEY', None),
+ ('text', 'TEXT', None),
+ ('from_trovehost', 'TEXT', None),
+ ('from_path', 'TEXT', None),
+ ('running_job', 'INT', None),
+ ('last_run', 'INT', None),
+ ('interval', 'INT', None),
+ ('lorry_timeout', 'INT', None),
+ ('disk_usage', 'INT', None),
]
self.lorries_fields = list(self.initial_lorries_fields)
self.lorries_fields.extend([
- ('last_run_exit', 'TEXT'),
- ('last_run_error', 'TEXT'),
+ ('last_run_exit', 'TEXT', None),
+ ('last_run_error', 'TEXT', None),
])
self.lorries_booleans = [
]
@@ -133,7 +133,8 @@ class StateDB(object):
# Table for all the known lorries (the "run queue").
fields_sql = ', '.join(
- '%s %s' % (name, info) for name, info in self.initial_lorries_fields
+ '%s %s' % (column, info)
+ for column, info, key in self.initial_lorries_fields
)
c.execute('CREATE TABLE lorries (%s)' % fields_sql)
@@ -320,7 +321,9 @@ class StateDB(object):
(ls_last_run, trovehost))
def make_lorry_info_from_row(self, row):
- result = dict((t[0], row[i]) for i, t in enumerate(self.lorries_fields))
+ result = dict(
+ (key or column, row[i])
+ for i, (column, info, key) in enumerate(self.lorries_fields))
for field in self.lorries_booleans:
result[field] = bool(result[field])
return result