summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <ben.hutchings@codethink.co.uk>2020-05-07 19:27:34 +0100
committerBen Hutchings <ben.hutchings@codethink.co.uk>2020-06-01 18:34:56 +0100
commit8528382ef756a5e6d01d093217106446eef49e42 (patch)
treec668d53903ad81341a7c3e0babec4e7712f4ff68
parent6f237b32894e1fc1973834d6adc1c597ea0fa5f3 (diff)
downloadlorry-controller-bwh/statedb-cleanup.tar.gz
STATEDB: Rename 'from_trovehost' column of lorries to 'from_host'bwh/statedb-cleanup
Deferred beause I don't think we can rely on SQLite 3.25.0 yet. Related to #10.
-rw-r--r--lorrycontroller/migrations/0004-cleanup-lorries.py20
-rw-r--r--lorrycontroller/statedb.py48
2 files changed, 45 insertions, 23 deletions
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)')