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)
def _table_prefix(self, model): """ Return the proper table prefix (schema). Based on SHARED_APPS, TENANT_APPS, FORCED_TO_PUBLIC_MODELS settings and current schema. """ conn = self.connection app_label = model._meta.app_label if dotted_name(model) in FORCED_MODELS: schema = conn.PUBLIC_SCHEMA elif app_label in TENANT_APP_LABELS and not conn.schema_is_public(): schema = conn.schema else: assert app_label in SHARED_APP_LABELS schema = conn.PUBLIC_SCHEMA return conn.ops.quote_name(schema) + '.'