(cls_or_op=None, apply_to_proxy=True)
return cls_or_op
Decorator/wrapper for partitioned migrations/migration operations

    This is useful for apps that have both partitioned and non-
    partitioned models. App names having partitioned models should be
    added to `TEST_NON_SERIALIZED_APPS` (see dev_settings.py) if model
    creations will be partitioned.

    May be applied to entire migration class (as decorator) or to individual
    migration operations (as wrapper).

    :param cls_or_op: Migration class or Operation instance.
    :param apply_to_proxy: Set this to `True` when migrating functions
    that should be applied to the shard dbs, but not to the proxy. It
    will be necessary to wrap migration operations individually if some
    should be applied to the proxy (table modifications) while some should
    only be applied to shard dbs (function modifications).
Decorator/wrapper for partitioned migrations/migration operations
Decorator / wrapper for partitioned migrations / migration operations
def partitioned(cls_or_op=None, apply_to_proxy=True):
    """Decorator/wrapper for partitioned migrations/migration operations

    This is useful for apps that have both partitioned and non-
    partitioned models. App names having partitioned models should be
    added to `TEST_NON_SERIALIZED_APPS` (see dev_settings.py) if model
    creations will be partitioned.

    May be applied to entire migration class (as decorator) or to individual
    migration operations (as wrapper).

    :param cls_or_op: Migration class or Operation instance.
    :param apply_to_proxy: Set this to `True` when migrating functions
    that should be applied to the shard dbs, but not to the proxy. It
    will be necessary to wrap migration operations individually if some
    should be applied to the proxy (table modifications) while some should
    only be applied to shard dbs (function modifications).
    """
    if cls_or_op is None:
        # decorator usage pattern: @partitioned(apply_to_proxy=False)
        def partitioned_decorator(cls_or_proxy):
            assert cls_or_proxy is not None
            return partitioned(cls_or_proxy, apply_to_proxy)
        return partitioned_decorator
    operation_methods = ["database_forwards", "database_backwards"]
    if all(hasattr(cls_or_op, m) for m in operation_methods):
        for name in operation_methods:
            # monkey-patch to override method because Django uses
            # isinstance(operation, ...) extensively, so we cannot
            # easily create a proxy class that quacks but doesn't have
            # the same type as the operation it proxies to.
            setattr(cls_or_op, name, partitioned_override(
                getattr(cls_or_op, name),
                apply_to_proxy
            ))
        return cls_or_op
    cls_or_op.operations = [
        partitioned(op, apply_to_proxy) for op in cls_or_op.operations
    ]
    return cls_or_op
def partitioned ( cls_or_op = None , apply_to_proxy = True ) : if cls_or_op is None : # decorator usage pattern: @partitioned(apply_to_proxy=False) def partitioned_decorator ( cls_or_proxy ) : assert cls_or_proxy is not None return partitioned ( cls_or_proxy , apply_to_proxy ) return partitioned_decorator operation_methods = [ "database_forwards" , "database_backwards" ] if all ( hasattr ( cls_or_op , m ) for m in operation_methods ) : for name in operation_methods : # monkey-patch to override method because Django uses # isinstance(operation, ...) extensively, so we cannot # easily create a proxy class that quacks but doesn't have # the same type as the operation it proxies to. setattr ( cls_or_op , name , partitioned_override ( getattr ( cls_or_op , name ) , apply_to_proxy ) ) return cls_or_op cls_or_op . operations = [ partitioned ( op , apply_to_proxy ) for op in cls_or_op . operations ] return cls_or_op