diff options
author | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-05-06 22:14:00 +0100 |
---|---|---|
committer | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-06-01 15:26:47 +0100 |
commit | 5963f66a434d49a4a6e8dfc02cfe256c88d1e1e6 (patch) | |
tree | 77da19156fa89124a7a22a4e40cc60962ec7dbda /lorrycontroller/statedb.py | |
parent | 68cc92a192d1c48e8abad7615239f941059fca47 (diff) | |
download | lorry-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".
Diffstat (limited to 'lorrycontroller/statedb.py')
-rw-r--r-- | lorrycontroller/statedb.py | 29 |
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 |