diff --git a/rattail_tempmon/db/alembic/versions/e9eb7fc0a451_add_client_archived.py b/rattail_tempmon/db/alembic/versions/e9eb7fc0a451_add_client_archived.py new file mode 100644 index 0000000..8ad7f86 --- /dev/null +++ b/rattail_tempmon/db/alembic/versions/e9eb7fc0a451_add_client_archived.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8; -*- +"""add client.archived + +Revision ID: e9eb7fc0a451 +Revises: 75c09e11543c +Create Date: 2018-09-28 12:12:19.813042 + +""" + +from __future__ import unicode_literals, absolute_import + +# revision identifiers, used by Alembic. +revision = 'e9eb7fc0a451' +down_revision = u'75c09e11543c' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa +import rattail.db.types + + + +def upgrade(): + + # client + op.add_column('client', sa.Column('archived', sa.Boolean(), nullable=True)) + client = sa.sql.table('client', sa.sql.column('archived')) + op.execute(client.update().values({'archived': False})) + op.alter_column('client', 'archived', nullable=False) + + +def downgrade(): + + # client + op.drop_column('client', 'archived') diff --git a/rattail_tempmon/db/model.py b/rattail_tempmon/db/model.py index 208012b..bf1bfd2 100644 --- a/rattail_tempmon/db/model.py +++ b/rattail_tempmon/db/model.py @@ -63,6 +63,14 @@ class Client(Base): enabled = sa.Column(sa.Boolean(), nullable=False, default=False) online = sa.Column(sa.Boolean(), nullable=False, default=False) + archived = sa.Column(sa.Boolean(), nullable=False, default=False, doc=""" + Flag indicating this client is "archived". This typically means that the + client itself no longer exists etc. but that the configuration for it + should be retained, e.g. to be used as a reference later etc. Note that + "archiving" a client is different from "disabling" it; the latter being + more temporary. + """) + def __str__(self): return '{} ({})'.format(self.config_key, self.hostname) diff --git a/rattail_tempmon/problems.py b/rattail_tempmon/problems.py index 7999b22..edb28af 100644 --- a/rattail_tempmon/problems.py +++ b/rattail_tempmon/problems.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2018 Lance Edgar # # This file is part of Rattail. # @@ -32,14 +32,16 @@ from rattail_tempmon.db import Session as TempmonSession, model as tempmon def disabled_probes(config, progress=None): """ - Notifies if any Tempmon client devices or probes are disabled. + Notifies if any (non-archived) Tempmon client devices or probes are disabled. """ tempmon_session = TempmonSession() clients = tempmon_session.query(tempmon.Client)\ + .filter(tempmon.Client.archived == False)\ .filter(tempmon.Client.enabled == False)\ .all() probes = tempmon_session.query(tempmon.Probe)\ .join(tempmon.Client)\ + .filter(tempmon.Client.archived == False)\ .filter(tempmon.Client.enabled == True)\ .filter(tempmon.Probe.enabled == False)\ .all()