From d2cbc43175eeb4a770f7dae2e984df3f994dcfb8 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Piedehierro Date: Sat, 8 Jul 2017 03:21:17 +0100 Subject: statedb: add columns for last failure information --- .../0002-add-last_run-status-columns-to-lorries.py | 20 ++++++++++++++++++++ lorrycontroller/statedb.py | 11 ++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 lorrycontroller/migrations/0002-add-last_run-status-columns-to-lorries.py diff --git a/lorrycontroller/migrations/0002-add-last_run-status-columns-to-lorries.py b/lorrycontroller/migrations/0002-add-last_run-status-columns-to-lorries.py new file mode 100644 index 0000000..ce30edf --- /dev/null +++ b/lorrycontroller/migrations/0002-add-last_run-status-columns-to-lorries.py @@ -0,0 +1,20 @@ +# Copyright (C) 2017 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 +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +import yoyo + +yoyo.step('ALTER TABLE lorries ADD COLUMN last_run_exit') +yoyo.step('ALTER TABLE lorries ADD COLUMN last_run_error') diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py index 1b885d9..8c62a31 100644 --- a/lorrycontroller/statedb.py +++ b/lorrycontroller/statedb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2016 Codethink Limited +# Copyright (C) 2014-2017 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 @@ -57,7 +57,7 @@ class StateDB(object): self._transaction_started = None def _open(self): - self.lorries_fields = [ + self.initial_lorries_fields = [ ('path', 'TEXT PRIMARY KEY'), ('text', 'TEXT'), ('from_trovehost', 'TEXT'), @@ -68,6 +68,11 @@ class StateDB(object): ('lorry_timeout', 'INT'), ('disk_usage', 'INT'), ] + self.lorries_fields = list(self.initial_lorries_fields) + self.lorries_fields.extend([ + ('last_run_exit', 'TEXT'), + ('last_run_error', 'TEXT'), + ]) self.lorries_booleans = [ ] @@ -118,7 +123,7 @@ class StateDB(object): # Table for all the known lorries (the "run queue"). fields_sql = ', '.join( - '%s %s' % (name, info) for name, info in self.lorries_fields + '%s %s' % (name, info) for name, info in self.initial_lorries_fields ) c.execute('CREATE TABLE lorries (%s)' % fields_sql) -- cgit v1.2.1