Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 def process_response(self, request, response):
     tenant = conn.TENANT_MODEL.objects.get(schema=conn.schema)
     c = conn.cursor()
     c.execute('SHOW search_path')
     search_path = c.fetchone()[0]
     self.record_stats({
         'tenant': {'domain': tenant.domain, 'schema': tenant.schema},
         'connection': [('schema', conn.schema), ('PUBLIC_SCHEMA', conn.PUBLIC_SCHEMA),
                        ('schema_is_public()', conn.schema_is_public()),
                        ('search_path', search_path),
                        ('TENANT_MODELS', TENANT_APP_LABELS),
                        ('SHARED_MODELS', SHARED_APP_LABELS),
                        ('FORCED_MODELS:', FORCED_MODELS)]
     })