remove changes_text column

This commit is contained in:
dishantsethi 2024-02-10 15:59:28 +05:30
parent 18aa0b5149
commit 6f4af0cfbe
3 changed files with 24 additions and 14 deletions

View file

@ -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:

View file

@ -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",
),
]

View file

@ -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: