From 6f4af0cfbec6ecea93c0a7fd74de6dfe3025cf8b Mon Sep 17 00:00:00 2001 From: dishantsethi Date: Sat, 10 Feb 2024 15:59:28 +0530 Subject: [PATCH] remove changes_text column --- .../commands/auditlogmigratejson.py | 11 +-------- .../migrations/0017_auto_20240210_1014.py | 23 +++++++++++++++++++ auditlog/models.py | 4 ---- 3 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 auditlog/migrations/0017_auto_20240210_1014.py diff --git a/auditlog/management/commands/auditlogmigratejson.py b/auditlog/management/commands/auditlogmigratejson.py index 44871a8..f0c3da7 100644 --- a/auditlog/management/commands/auditlogmigratejson.py +++ b/auditlog/management/commands/auditlogmigratejson.py @@ -79,9 +79,7 @@ class Command(BaseCommand): return False def get_logs(self): - return LogEntry.objects.filter( - changes_text__isnull=False, changes__isnull=True - ).exclude(changes_text__exact="") + return LogEntry.objects.filter(changes__isnull=True) def migrate_using_django(self, batch_size): def _apply_django_migration(_logs) -> int: @@ -89,13 +87,6 @@ class Command(BaseCommand): updated = [] errors = [] - for log in _logs: - try: - log.changes = json.loads(log.changes_text) - except ValueError: - errors.append(log.id) - else: - updated.append(log) LogEntry.objects.bulk_update(updated, fields=["changes"]) if errors: diff --git a/auditlog/migrations/0017_auto_20240210_1014.py b/auditlog/migrations/0017_auto_20240210_1014.py new file mode 100644 index 0000000..6494f6d --- /dev/null +++ b/auditlog/migrations/0017_auto_20240210_1014.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.19 on 2024-02-10 10:14 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("auditlog", "0016_auto_20240210_0934"), + ] + + operations = [ + migrations.RenameField( + model_name="logentry", + old_name="object_repr", + new_name="object_representation", + ), + migrations.RenameField( + model_name="logentry", + old_name="object_pk", + new_name="record", + ), + ] diff --git a/auditlog/models.py b/auditlog/models.py index e6e5d8d..575a4fc 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -300,7 +300,6 @@ class LogEntry(models.Model): action = models.PositiveSmallIntegerField( choices=Action.choices, verbose_name=_("action"), db_index=True ) - changes_text = models.TextField(blank=True, verbose_name=_("change message")) changes = models.JSONField(null=True, verbose_name=_("change message")) timestamp = models.DateTimeField( default=django_timezone.now, @@ -510,9 +509,6 @@ def _changes_func() -> Callable[[LogEntry], Dict]: def json_then_text(instance: LogEntry) -> Dict: if instance.changes: return instance.changes - elif instance.changes_text: - with contextlib.suppress(ValueError): - return json.loads(instance.changes_text) return {} def default(instance: LogEntry) -> Dict: