فهرست منبع

fix(api): make sure RRset.touched can't be NULL

Peter Thomassen 5 سال پیش
والد
کامیت
18663cd1cd
2فایلهای تغییر یافته به همراه25 افزوده شده و 3 حذف شده
  1. 24 0
      api/desecapi/migrations/0015_rrset_touched_auto_now.py
  2. 1 3
      api/desecapi/models.py

+ 24 - 0
api/desecapi/migrations/0015_rrset_touched_auto_now.py

@@ -0,0 +1,24 @@
+# Generated by Django 3.0.6 on 2020-05-22 12:10
+
+from django.db import migrations, models
+
+
+def migrate_data(apps, schema_editor):
+    RRset = apps.get_model('desecapi', 'RRset')
+    RRset.objects.filter(touched__isnull=True).update(touched=models.F('created'))
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('desecapi', '0014_rrset_touched'),
+    ]
+
+    operations = [
+        migrations.RunPython(migrate_data, migrations.RunPython.noop),
+        migrations.AlterField(
+            model_name='rrset',
+            name='touched',
+            field=models.DateTimeField(auto_now=True),
+        ),
+    ]

+ 1 - 3
api/desecapi/models.py

@@ -6,7 +6,6 @@ import secrets
 import string
 import string
 import time
 import time
 import uuid
 import uuid
-from base64 import urlsafe_b64encode
 from datetime import timedelta
 from datetime import timedelta
 from hashlib import sha256
 from hashlib import sha256
 
 
@@ -380,7 +379,7 @@ class RRsetManager(Manager):
 class RRset(ExportModelOperationsMixin('RRset'), models.Model):
 class RRset(ExportModelOperationsMixin('RRset'), models.Model):
     id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
     id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
     created = models.DateTimeField(auto_now_add=True)
     created = models.DateTimeField(auto_now_add=True)
-    touched = models.DateTimeField(null=True)
+    touched = models.DateTimeField(auto_now=True)
     domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
     domain = models.ForeignKey(Domain, on_delete=models.CASCADE)
     subname = models.CharField(
     subname = models.CharField(
         max_length=178,
         max_length=178,
@@ -425,7 +424,6 @@ class RRset(ExportModelOperationsMixin('RRset'), models.Model):
         return self.construct_name(self.subname, self.domain.name)
         return self.construct_name(self.subname, self.domain.name)
 
 
     def save(self, *args, **kwargs):
     def save(self, *args, **kwargs):
-        self.touched = timezone.now()
         self.full_clean(validate_unique=False)
         self.full_clean(validate_unique=False)
         super().save(*args, **kwargs)
         super().save(*args, **kwargs)