2019-01-11 13:48:22 +01:00
|
|
|
from django.db import migrations, models
|
2022-05-27 23:33:51 +02:00
|
|
|
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
|
2020-01-14 21:59:46 +01:00
|
|
|
from django.db.migrations.state import StateApps
|
2019-01-11 13:48:22 +01:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2022-05-27 23:33:51 +02:00
|
|
|
def render_all_stream_descriptions(
|
|
|
|
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
|
|
|
|
) -> None:
|
2022-02-23 04:56:18 +01:00
|
|
|
# FIXME: Application code should not be imported from migrations.
|
|
|
|
from zerver.lib.streams import render_stream_description
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
Stream = apps.get_model("zerver", "Stream")
|
|
|
|
all_streams = Stream.objects.exclude(description="")
|
2019-01-11 13:48:22 +01:00
|
|
|
for stream in all_streams:
|
2022-10-29 20:52:47 +02:00
|
|
|
stream.rendered_description = render_stream_description(stream.description, stream.realm)
|
2019-01-11 13:48:22 +01:00
|
|
|
stream.save(update_fields=["rendered_description"])
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("zerver", "0205_remove_realmauditlog_requires_billing_update"),
|
2019-01-11 13:48:22 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
2021-02-12 08:20:45 +01:00
|
|
|
model_name="stream",
|
|
|
|
name="rendered_description",
|
|
|
|
field=models.TextField(default=""),
|
2019-01-11 13:48:22 +01:00
|
|
|
),
|
2021-02-12 08:19:30 +01:00
|
|
|
migrations.RunPython(
|
|
|
|
render_all_stream_descriptions, reverse_code=migrations.RunPython.noop, elidable=True
|
|
|
|
),
|
2019-01-11 13:48:22 +01:00
|
|
|
]
|