def handle(self, *args, **options): verbosity = options.get('verbosity', 1) # First check if public schema is synced already write = self.stdout.write if len(args) == 0: raise CommandError('You need to specify schema names to sync!') if args[0] != conn.PUBLIC_SCHEMA: conn.schema = conn.PUBLIC_SCHEMA # There are no tables in public schema if not conn.introspection.table_names(): raise CommandError('You should sync the public schema first!') for schema in args: conn.schema = schema if not conn.schema_exists(schema): conn.create_schema(schema) auth_user_not_in_tenant = 'auth.User' in FORCED_MODELS or 'auth' not in TENANT_APP_LABELS if (conn.schema_is_public() and not is_shared(auth_app.User) or (not conn.schema_is_public() and auth_user_not_in_tenant)): if verbosity > 1: write("Disconnect auth.User signal handlers, as it is not synced...") post_syncdb.disconnect(create_permissions, dispatch_uid="django.contrib.auth.management.create_permissions") post_syncdb.disconnect(create_superuser, sender=auth_app, dispatch_uid="django.contrib.auth.management.create_superuser") call_command('syncdb', **options)
def _create_for_schema(self, model): """ Decide if model need to be created for the current schema. Returns True or False. """ return (self.connection.schema_is_public() and is_shared(model) or not self.connection.schema_is_public() and # don't re-create models already synced to public schema model._meta.app_label in TENANT_APP_LABELS and dotted_name(model) not in FORCED_MODELS)