mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	A migration should not import zerver.lib.streams at all, but this solves the immediate problem with check-database-compatibility.py. Signed-off-by: Anders Kaseorg <anders@zulip.com>
		
			
				
	
	
		
			33 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from django.db import migrations, models
 | 
						|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
 | 
						|
from django.db.migrations.state import StateApps
 | 
						|
 | 
						|
 | 
						|
def render_all_stream_descriptions(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
 | 
						|
    # FIXME: Application code should not be imported from migrations.
 | 
						|
    from zerver.lib.streams import render_stream_description
 | 
						|
 | 
						|
    Stream = apps.get_model("zerver", "Stream")
 | 
						|
    all_streams = Stream.objects.exclude(description="")
 | 
						|
    for stream in all_streams:
 | 
						|
        stream.rendered_description = render_stream_description(stream.description)
 | 
						|
        stream.save(update_fields=["rendered_description"])
 | 
						|
 | 
						|
 | 
						|
class Migration(migrations.Migration):
 | 
						|
 | 
						|
    dependencies = [
 | 
						|
        ("zerver", "0205_remove_realmauditlog_requires_billing_update"),
 | 
						|
    ]
 | 
						|
 | 
						|
    operations = [
 | 
						|
        migrations.AddField(
 | 
						|
            model_name="stream",
 | 
						|
            name="rendered_description",
 | 
						|
            field=models.TextField(default=""),
 | 
						|
        ),
 | 
						|
        migrations.RunPython(
 | 
						|
            render_all_stream_descriptions, reverse_code=migrations.RunPython.noop, elidable=True
 | 
						|
        ),
 | 
						|
    ]
 |