snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
71
zerver/migrations/0093_subscription_event_log_backfill.py
Normal file
71
zerver/migrations/0093_subscription_event_log_backfill.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from django.db import migrations, models
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.migrations.state import StateApps
|
||||
from django.db.models import Max
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
|
||||
def backfill_subscription_log_events(
|
||||
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
|
||||
) -> None:
|
||||
migration_time = timezone_now()
|
||||
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
|
||||
Subscription = apps.get_model("zerver", "Subscription")
|
||||
Message = apps.get_model("zerver", "Message")
|
||||
objects_to_create = []
|
||||
|
||||
subs_query = Subscription.objects.select_related(
|
||||
"user_profile", "user_profile__realm", "recipient"
|
||||
).filter(recipient__type=2)
|
||||
for sub in subs_query:
|
||||
entry = RealmAuditLog(
|
||||
realm=sub.user_profile.realm,
|
||||
modified_user=sub.user_profile,
|
||||
modified_stream_id=sub.recipient.type_id,
|
||||
event_last_message_id=0,
|
||||
event_type="subscription_created",
|
||||
event_time=migration_time,
|
||||
backfilled=True,
|
||||
)
|
||||
objects_to_create.append(entry)
|
||||
RealmAuditLog.objects.bulk_create(objects_to_create)
|
||||
objects_to_create = []
|
||||
|
||||
event_last_message_id = Message.objects.aggregate(Max("id"))["id__max"]
|
||||
migration_time_for_deactivation = timezone_now()
|
||||
for sub in subs_query.filter(active=False):
|
||||
entry = RealmAuditLog(
|
||||
realm=sub.user_profile.realm,
|
||||
modified_user=sub.user_profile,
|
||||
modified_stream_id=sub.recipient.type_id,
|
||||
event_last_message_id=event_last_message_id,
|
||||
event_type="subscription_deactivated",
|
||||
event_time=migration_time_for_deactivation,
|
||||
backfilled=True,
|
||||
)
|
||||
objects_to_create.append(entry)
|
||||
RealmAuditLog.objects.bulk_create(objects_to_create)
|
||||
objects_to_create = []
|
||||
|
||||
|
||||
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
||||
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
|
||||
RealmAuditLog.objects.filter(event_type="subscription_created").delete()
|
||||
RealmAuditLog.objects.filter(event_type="subscription_deactivated").delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("zerver", "0092_create_scheduledemail"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="realmauditlog",
|
||||
name="event_last_message_id",
|
||||
field=models.IntegerField(null=True),
|
||||
),
|
||||
migrations.RunPython(
|
||||
backfill_subscription_log_events, reverse_code=reverse_code, elidable=True
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user