forked from GithubBackups/healthchecks
Add Ping.kind field
This commit is contained in:
parent
be4c4f7a26
commit
7480eca2a5
@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
|
||||
### Improvements
|
||||
- Database schema: set Check.user to not null
|
||||
- Database schema: add uniqueness constraint to Check.code
|
||||
- Database schema: add Ping.kind field
|
||||
|
||||
|
||||
## 1.4.0 - 2018-12-25
|
||||
|
18
hc/api/migrations/0050_ping_kind.py
Normal file
18
hc/api/migrations/0050_ping_kind.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 2.1.4 on 2019-01-04 09:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0049_auto_20190102_0743'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='ping',
|
||||
name='kind',
|
||||
field=models.CharField(blank=True, max_length=6, null=True),
|
||||
),
|
||||
]
|
24
hc/api/migrations/0051_auto_20190104_0908.py
Normal file
24
hc/api/migrations/0051_auto_20190104_0908.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Generated by Django 2.1.4 on 2019-01-04 09:08
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def fill_ping_kind(apps, schema_editor):
|
||||
Ping = apps.get_model('api', 'Ping')
|
||||
|
||||
q = Ping.objects.filter(start=True)
|
||||
q.update(kind="start")
|
||||
|
||||
q = Ping.objects.filter(fail=True)
|
||||
q.update(kind="fail")
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0050_ping_kind'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(fill_ping_kind),
|
||||
]
|
@ -230,8 +230,14 @@ class Check(models.Model):
|
||||
|
||||
ping = Ping(owner=self)
|
||||
ping.n = self.n_pings
|
||||
ping.start = action == "start"
|
||||
ping.fail = action == "fail"
|
||||
|
||||
if action == "start":
|
||||
ping.start = True
|
||||
ping.kind = "start"
|
||||
elif action == "fail":
|
||||
ping.fail = True
|
||||
ping.kind = "fail"
|
||||
|
||||
ping.remote_addr = remote_addr
|
||||
ping.scheme = scheme
|
||||
ping.method = method
|
||||
@ -246,6 +252,7 @@ class Ping(models.Model):
|
||||
n = models.IntegerField(null=True)
|
||||
owner = models.ForeignKey(Check, models.CASCADE)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
kind = models.CharField(max_length=6, blank=True, null=True)
|
||||
start = models.NullBooleanField(default=False)
|
||||
fail = models.NullBooleanField(default=False)
|
||||
scheme = models.CharField(max_length=10, default="http")
|
||||
|
@ -23,6 +23,7 @@ class PingTestCase(BaseTestCase):
|
||||
|
||||
ping = Ping.objects.latest("id")
|
||||
self.assertEqual(ping.scheme, "http")
|
||||
self.assertEqual(ping.kind, None)
|
||||
|
||||
def test_it_changes_status_of_paused_check(self):
|
||||
self.check.status = "paused"
|
||||
@ -139,6 +140,7 @@ class PingTestCase(BaseTestCase):
|
||||
|
||||
ping = Ping.objects.get()
|
||||
self.assertTrue(ping.fail)
|
||||
self.assertEqual(ping.kind, "fail")
|
||||
|
||||
flip = Flip.objects.get()
|
||||
self.assertEqual(flip.owner, self.check)
|
||||
@ -158,6 +160,7 @@ class PingTestCase(BaseTestCase):
|
||||
|
||||
ping = Ping.objects.get()
|
||||
self.assertTrue(ping.start)
|
||||
self.assertEqual(ping.kind, "start")
|
||||
|
||||
def test_start_does_not_change_status_of_paused_check(self):
|
||||
self.check.status = "paused"
|
||||
|
Loading…
x
Reference in New Issue
Block a user