psqlextra/backend/hstore_unique.py
def alter_field(self, model, old_field, new_field, strict=False):
        """Ran when the configuration on a field changed."""

        is_old_field_hstore = isinstance(old_field, HStoreField)
        is_new_field_hstore = isinstance(new_field, HStoreField)

        if not is_old_field_hstore and not is_new_field_hstore:
            return

        old_uniqueness = getattr(old_field, 'uniqueness', []) or []
        new_uniqueness = getattr(new_field, 'uniqueness', []) or []

        # handle field renames before moving on
        if str(old_field.column) != str(new_field.column):
            for keys in self._iterate_uniqueness_keys(old_field):
                self._rename_hstore_unique(
                    model._meta.db_table,
                    model._meta.db_table,
                    old_field,
                    new_field,
                    keys
                )

        # drop the indexes for keys that have been removed
        for keys in old_uniqueness:
            if keys not in new_uniqueness:
                self._drop_hstore_unique(
                    model,
                    old_field,
                    self._compose_keys(keys)
                )

        # create new indexes for keys that have been added
        for keys in new_uniqueness:
            if keys not in old_uniqueness:
                self._create_hstore_unique(
                    model,
                    new_field,
                    self._compose_keys(keys)
                )
def alter_field(self, model, old_field, new_field, strict=False):
        """Ran when the configuration on a field changed."""

        is_old_field_hstore = isinstance(old_field, HStoreField)
        is_new_field_hstore = isinstance(new_field, HStoreField)

        if not is_old_field_hstore and not is_new_field_hstore:
            return

        old_uniqueness = getattr(old_field, 'uniqueness', []) or []
        new_uniqueness = getattr(new_field, 'uniqueness', []) or []

        # handle field renames before moving on
        if str(old_field.column) != str(new_field.column):
            for keys in self._iterate_uniqueness_keys(old_field):
                self._rename_hstore_unique(
                    model._meta.db_table,
                    model._meta.db_table,
                    old_field,
                    new_field,
                    keys
                )

        # drop the indexes for keys that have been removed
        for keys in old_uniqueness:
            if keys not in new_uniqueness:
                self._drop_hstore_unique(
                    model,
                    old_field,
                    self._compose_keys(keys)
                )

        # create new indexes for keys that have been added
        for keys in new_uniqueness:
            if keys not in old_uniqueness:
                self._create_hstore_unique(
                    model,
                    new_field,
                    self._compose_keys(keys)
                )
def alter_field ( self , model , old_field , new_field , strict = False ) : is_old_field_hstore = isinstance ( old_field , HStoreField ) is_new_field_hstore = isinstance ( new_field , HStoreField ) if not is_old_field_hstore and not is_new_field_hstore : return old_uniqueness = getattr ( old_field , 'uniqueness' , [ ] ) or [ ] new_uniqueness = getattr ( new_field , 'uniqueness' , [ ] ) or [ ] # handle field renames before moving on if str ( old_field . column ) != str ( new_field . column ) : for keys in self . _iterate_uniqueness_keys ( old_field ) : self . _rename_hstore_unique ( model . _meta . db_table , model . _meta . db_table , old_field , new_field , keys ) # drop the indexes for keys that have been removed for keys in old_uniqueness : if keys not in new_uniqueness : self . _drop_hstore_unique ( model , old_field , self . _compose_keys ( keys ) ) # create new indexes for keys that have been added for keys in new_uniqueness : if keys not in old_uniqueness : self . _create_hstore_unique ( model , new_field , self . _compose_keys ( keys ) )
Ran when the configuration on a field changed.
Ran when the configuration on a field changed .