mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Because we create all realms with do_create_user (including in the test suite), we just need to change that function, add a migration for existing realms, and ensure the data import code path correctly creates these objects. Note that the import code path will create a RealmUserDefault row with default values if it is not present in the import data, which is important for importing data from other tools like Slack.
		
			
				
	
	
		
			30 lines
		
	
	
		
			980 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			980 B
		
	
	
	
		
			Python
		
	
	
	
	
	
# Generated by Django 3.2.2 on 2021-06-01 16:19
 | 
						|
 | 
						|
from django.db import migrations
 | 
						|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
 | 
						|
from django.db.migrations.state import StateApps
 | 
						|
 | 
						|
 | 
						|
def create_realm_user_default_table(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
 | 
						|
    Realm = apps.get_model("zerver", "Realm")
 | 
						|
    RealmUserDefault = apps.get_model("zerver", "RealmUserDefault")
 | 
						|
    realms = Realm.objects.all()
 | 
						|
    realm_user_default_objects = []
 | 
						|
    for realm in realms:
 | 
						|
        realm_user_default = RealmUserDefault(realm=realm)
 | 
						|
        realm_user_default_objects.append(realm_user_default)
 | 
						|
    RealmUserDefault.objects.bulk_create(realm_user_default_objects)
 | 
						|
 | 
						|
 | 
						|
class Migration(migrations.Migration):
 | 
						|
 | 
						|
    dependencies = [
 | 
						|
        ("zerver", "0345_alter_realm_name"),
 | 
						|
    ]
 | 
						|
 | 
						|
    operations = [
 | 
						|
        migrations.RunPython(
 | 
						|
            create_realm_user_default_table, reverse_code=migrations.RunPython.noop, elidable=True
 | 
						|
        ),
 | 
						|
    ]
 |