Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
retention: Add .restored_timestamp to ArchiveTransaction.
Mateusz Mandera224ea3aaed47
diff --git a/zerver/lib/retention.py b/zerver/lib/retention.pyindex 76cefc25117..a32cd751d6d 100644--- a/zerver/lib/retention.py+++ b/zerver/lib/retention.py@@ -587,6 +587,7 @@ def restore_data_from_archive(archive_transaction: ArchiveTransaction) -> int:restore_attachment_messages_from_archive(archive_transaction.id)archive_transaction.restored = True+ archive_transaction.restored_timestamp = timezone_now()archive_transaction.save()logger.info("Finished. Restored %s messages", len(msg_ids))diff --git a/zerver/migrations/0519_archivetransaction_restored_timestamp.py b/zerver/migrations/0519_archivetransaction_restored_timestamp.pynew file mode 100644index 00000000000..dee30d3edd9--- /dev/null+++ b/zerver/migrations/0519_archivetransaction_restored_timestamp.py@@ -0,0 +1,17 @@+# Generated by Django 5.0.6 on 2024-05-08 00:59++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("zerver", "0518_merge"),+ ]++ operations = [+ migrations.AddField(+ model_name="archivetransaction",+ name="restored_timestamp",+ field=models.DateTimeField(db_index=True, null=True),+ ),+ ]diff --git a/zerver/models/messages.py b/zerver/models/messages.pyindex 46547e77f2b..45ff2b7d7f4 100644--- a/zerver/models/messages.py+++ b/zerver/models/messages.py@@ -91,6 +91,7 @@ class ArchiveTransaction(models.Model):timestamp = models.DateTimeField(default=timezone_now, db_index=True)# Marks if the data archived in this transaction has been restored:restored = models.BooleanField(default=False, db_index=True)+ restored_timestamp = models.DateTimeField(null=True, db_index=True)type = models.PositiveSmallIntegerField(db_index=True)# Valid types:diff --git a/zerver/tests/test_retention.py b/zerver/tests/test_retention.pyindex 5e1536c61a6..ee696dc4f23 100644--- a/zerver/tests/test_retention.py+++ b/zerver/tests/test_retention.py@@ -2,6 +2,7 @@ from datetime import datetime, timedeltafrom typing import Any, Dict, List, Optional, Tuplefrom unittest import mock+import time_machinefrom django.conf import settingsfrom django.utils.timezone import now as timezone_nowfrom typing_extensions import override@@ -466,11 +467,15 @@ class TestArchiveMessagesGeneral(ArchiveMessagesTestingBase):transactions = ArchiveTransaction.objects.all()self.assert_length(transactions, 2) # With chunk_size 4, there should be 2 transactions- restore_all_data_from_archive()+ now = timezone_now()+ with time_machine.travel(now, tick=False):+ restore_all_data_from_archive()transactions[0].refresh_from_db()transactions[1].refresh_from_db()self.assertTrue(transactions[0].restored)self.assertTrue(transactions[1].restored)+ self.assertEqual(transactions[0].restored_timestamp, now)+ self.assertEqual(transactions[1].restored_timestamp, now)archive_messages(chunk_size=10)self._verify_archive_data(expired_msg_ids, expired_usermsg_ids)