mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	This is a preparatory commit for using isort for sorting all of our imports, merging changes to files where we can easily review the changes as something we're happy with. These are also files with relatively little active development, which means we don't expect much merge conflict risk from these changes.
		
			
				
	
	
		
			25 lines
		
	
	
		
			872 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			872 B
		
	
	
	
		
			Python
		
	
	
	
	
	
# -*- coding: utf-8 -*-
 | 
						|
from django.db import migrations
 | 
						|
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
 | 
						|
from django.db.migrations.state import StateApps
 | 
						|
 | 
						|
 | 
						|
def add_domain_to_realm_alias_if_needed(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
 | 
						|
    Realm = apps.get_model('zerver', 'Realm')
 | 
						|
    RealmAlias = apps.get_model('zerver', 'RealmAlias')
 | 
						|
 | 
						|
    for realm in Realm.objects.all():
 | 
						|
        # if realm.domain already exists in RealmAlias, assume it is correct
 | 
						|
        if not RealmAlias.objects.filter(domain=realm.domain).exists():
 | 
						|
            RealmAlias.objects.create(realm=realm, domain=realm.domain)
 | 
						|
 | 
						|
class Migration(migrations.Migration):
 | 
						|
 | 
						|
    dependencies = [
 | 
						|
        ('zerver', '0032_verify_all_medium_avatar_images'),
 | 
						|
    ]
 | 
						|
 | 
						|
    operations = [
 | 
						|
        migrations.RunPython(add_domain_to_realm_alias_if_needed)
 | 
						|
    ]
 |