From 8528382ef756a5e6d01d093217106446eef49e42 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 7 May 2020 19:27:34 +0100 Subject: STATEDB: Rename 'from_trovehost' column of lorries to 'from_host' Deferred beause I don't think we can rely on SQLite 3.25.0 yet. Related to #10. --- lorrycontroller/migrations/0004-cleanup-lorries.py | 20 +++++++++ lorrycontroller/statedb.py | 48 +++++++++++----------- 2 files changed, 45 insertions(+), 23 deletions(-) create mode 100644 lorrycontroller/migrations/0004-cleanup-lorries.py diff --git a/lorrycontroller/migrations/0004-cleanup-lorries.py b/lorrycontroller/migrations/0004-cleanup-lorries.py new file mode 100644 index 0000000..ab979e9 --- /dev/null +++ b/lorrycontroller/migrations/0004-cleanup-lorries.py @@ -0,0 +1,20 @@ +# Copyright (C) 2020 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 + + +# XXX Requires SQLite >= 3.25.0 +yoyo.step('ALTER TABLE lorries RENAME COLUMN from_trovehost TO from_host') diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py index 2dd30f0..64f96a5 100644 --- a/lorrycontroller/statedb.py +++ b/lorrycontroller/statedb.py @@ -56,22 +56,19 @@ class StateDB(object): self._conn = None self._transaction_started = None - self.initial_lorries_fields = [ - ('path', 'TEXT PRIMARY KEY', None), - ('text', 'TEXT', None), - ('from_trovehost', 'TEXT', 'from_host'), - ('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', None), - ('last_run_error', 'TEXT', None), - ]) + self.lorries_fields = [ + 'path', + 'text', + 'from_host', + 'from_path', + 'running_job', + 'last_run', + 'interval', + 'lorry_timeout', + 'disk_usage', + 'last_run_exit', + 'last_run_error', + ] self.lorries_booleans = [ ] @@ -136,13 +133,18 @@ class StateDB(object): ')') # Table for all the known lorries (the "run queue"). - - fields_sql = ', '.join( - '%s %s' % (column, info) - for column, info, key in self.initial_lorries_fields - ) - - c.execute('CREATE TABLE lorries (%s)' % fields_sql) + c.execute( + 'CREATE TABLE lorries (' + '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 ' + ')') # Table for the next available job id. c.execute('CREATE TABLE next_job_id (job_id INT)') -- cgit v1.2.1