Exemplo n.º 1
0
 def drop_columns(self, model, *names, **kwargs):
     """Remove fields from model."""
     fields = [field for field in model._meta.fields.values() if field.name in names]
     cascade = kwargs.pop('cascade', True)
     for field in fields:
         self.__del_field__(model, field)
         if field.unique:
             index_name = make_index_name(model._meta.table_name, [field.column_name])
             self.ops.append(self.migrator.drop_index(model._meta.table_name, index_name))
         self.ops.append(
             self.migrator.drop_column(
                 model._meta.table_name, field.column_name, cascade=cascade))
     return model
Exemplo n.º 2
0
 def drop_columns(self, model, *names, **kwargs):
     """Remove fields from model."""
     fields = [field for field in model._meta.fields.values() if field.name in names]
     cascade = kwargs.pop('cascade', True)
     for field in fields:
         self.__del_field__(model, field)
         if field.unique:
             index_name = make_index_name(model._meta.table_name, [field.column_name])
             self.ops.append(self.migrator.drop_index(model._meta.table_name, index_name))
         self.ops.append(
             self.migrator.drop_column(
                 model._meta.table_name, field.column_name, cascade=cascade))
     return model
Exemplo n.º 3
0
    def drop_index(self, model, *columns):
        """Drop indexes."""
        columns_ = []
        for col in columns:
            field = model._meta.fields.get(col)
            if len(columns) == 1:
                field.unique = field.index = False

            if isinstance(field, pw.ForeignKeyField):
                col = col + '_id'
            columns_.append(col)
        index_name = make_index_name(model._meta.table_name, columns_)
        model._meta.indexes = [(cols, _) for (cols, _) in model._meta.indexes
                               if columns != cols]
        self.ops.append(
            self.migrator.drop_index(model._meta.table_name, index_name))
        return model
Exemplo n.º 4
0
    def drop_index(self, model, *columns):
        """Drop indexes."""
        columns_ = []
        for col in columns:
            field = model._meta.fields.get(col)
            if not field:
                continue

            if len(columns) == 1:
                field.unique = field.index = False

            if isinstance(field, pw.ForeignKeyField):
                col = col + '_id'
            columns_.append(col)
        index_name = make_index_name(model._meta.table_name, columns_)
        model._meta.indexes = [(cols, _) for (cols, _) in model._meta.indexes if columns != cols]
        self.ops.append(self.migrator.drop_index(model._meta.table_name, index_name))
        return model