2021-12-30 23:51:38 +01:00
|
|
|
from django.db import migrations
|
2023-03-04 01:40:40 +01:00
|
|
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
2021-12-30 23:51:38 +01:00
|
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
|
|
|
|
|
|
|
def backfill_remote_zulip_server_creation_log_events(
|
2022-05-27 23:33:51 +02:00
|
|
|
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
|
2021-12-30 23:51:38 +01:00
|
|
|
) -> None:
|
|
|
|
RemoteZulipServer = apps.get_model("zilencer", "RemoteZulipServer")
|
|
|
|
RemoteZulipServerAuditLog = apps.get_model("zilencer", "RemoteZulipServerAuditLog")
|
|
|
|
RemoteZulipServerAuditLog.REMOTE_SERVER_CREATED = 10215
|
|
|
|
|
|
|
|
objects_to_create = []
|
|
|
|
for remote_server in RemoteZulipServer.objects.all():
|
|
|
|
entry = RemoteZulipServerAuditLog(
|
|
|
|
server=remote_server,
|
|
|
|
event_type=RemoteZulipServerAuditLog.REMOTE_SERVER_CREATED,
|
|
|
|
event_time=remote_server.last_updated,
|
|
|
|
backfilled=True,
|
|
|
|
)
|
|
|
|
objects_to_create.append(entry)
|
|
|
|
RemoteZulipServerAuditLog.objects.bulk_create(objects_to_create)
|
|
|
|
|
|
|
|
|
2022-05-27 23:33:51 +02:00
|
|
|
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
2021-12-30 23:51:38 +01:00
|
|
|
RemoteZulipServerAuditLog = apps.get_model("zilencer", "RemoteZulipServerAuditLog")
|
|
|
|
RemoteZulipServerAuditLog.REMOTE_SERVER_CREATED = 10215
|
|
|
|
RemoteZulipServerAuditLog.objects.filter(
|
|
|
|
event_type=RemoteZulipServerAuditLog.REMOTE_SERVER_CREATED, backfilled=True
|
|
|
|
).delete()
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
|
|
("zilencer", "0021_alter_remotezulipserver_uuid"),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.RunPython(
|
|
|
|
backfill_remote_zulip_server_creation_log_events,
|
|
|
|
reverse_code=reverse_code,
|
|
|
|
elidable=True,
|
|
|
|
)
|
|
|
|
]
|