Browse Source

Warn about obsolete `update_alert_after` trigger.

pull/109/head
Pēteris Caune 8 years ago
parent
commit
c6d5e64286
3 changed files with 26 additions and 2 deletions
  1. +1
    -2
      README.md
  2. +1
    -0
      hc/api/management/commands/droptriggers.py
  3. +24
    -0
      hc/api/models.py

+ 1
- 2
README.md View File

@ -52,11 +52,10 @@ in development environment.
$ psql --user postgres
postgres=# create database hc;
* create database tables, triggers, superuser:
* create database tables and the superuser account:
$ cd ~/webapps/healthchecks
$ ./manage.py migrate
$ ./manage.py ensuretriggers
$ ./manage.py createsuperuser
* run development server:


+ 1
- 0
hc/api/management/commands/droptriggers.py View File

@ -22,6 +22,7 @@ def _sqlite(cursor):
class Command(BaseCommand):
help = 'Drops the `update_alert_after` trigger'
requires_system_checks = False
def handle(self, *args, **options):
with connection.cursor() as cursor:


+ 24
- 0
hc/api/models.py View File

@ -7,6 +7,7 @@ from datetime import datetime, timedelta as td
from croniter import croniter
from django.conf import settings
from django.core.checks import Warning
from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse
@ -164,6 +165,29 @@ class Check(models.Model):
return result
@classmethod
def check(cls, **kwargs):
errors = super(Check, cls).check(**kwargs)
trigger_detected = False
try:
dummy = Check(last_ping=timezone.now())
dummy.save()
dummy.refresh_from_db()
trigger_detected = bool(dummy.alert_after)
dummy.delete()
except:
pass
if trigger_detected:
err = Warning(
"Obsolete 'update_alert_after' trigger exists in database.",
hint="Please remove the trigger with 'manage.py droptriggers'",
id="hc.api.E001")
errors.append(err)
return errors
class Ping(models.Model):
n = models.IntegerField(null=True)


Loading…
Cancel
Save