mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Sync django query and postgres query (#653)
* run postgres query for rows that changes is null for them and there is value for changes_text * add a test case to make when changes has value it wont be overwritten by changes_text
This commit is contained in:
parent
2c0bd0fac6
commit
5bb701d821
2 changed files with 22 additions and 1 deletions
|
|
@ -125,7 +125,13 @@ class Command(BaseCommand):
|
|||
def postgres():
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
'UPDATE auditlog_logentry SET changes="changes_text"::jsonb'
|
||||
"""
|
||||
UPDATE auditlog_logentry
|
||||
SET changes="changes_text"::jsonb
|
||||
WHERE changes_text IS NOT NULL
|
||||
AND changes_text <> ''
|
||||
AND changes IS NULL
|
||||
"""
|
||||
)
|
||||
return cursor.cursor.rowcount
|
||||
|
||||
|
|
|
|||
|
|
@ -135,6 +135,21 @@ class AuditlogMigrateJsonTest(TestCase):
|
|||
self.assertEqual(errbuf, "")
|
||||
self.assertIsNotNone(log_entry.changes)
|
||||
|
||||
def test_native_postgres_changes_not_overwritten(self):
|
||||
# Arrange
|
||||
log_entry = self.make_logentry()
|
||||
log_entry.changes = original_changes = {"key": "value"}
|
||||
log_entry.changes_text = '{"key": "new value"}'
|
||||
log_entry.save()
|
||||
|
||||
# Act
|
||||
outbuf, errbuf = self.call_command("-d=postgres")
|
||||
log_entry.refresh_from_db()
|
||||
|
||||
# Assert
|
||||
self.assertEqual(errbuf, "")
|
||||
self.assertEqual(log_entry.changes, original_changes)
|
||||
|
||||
def test_native_unsupported(self):
|
||||
# Arrange
|
||||
log_entry = self.make_logentry()
|
||||
|
|
|
|||
Loading…
Reference in a new issue