class Meta: indexes = [ BTreeIndex(fields=["year"]), BTreeIndex(fields=["script_type"]), GinIndex(fields=["search_content"]) ] ordering = ['title']
class Meta: indexes = [ HashIndex(fields=["sent_by"]), HashIndex(fields=["status"]), HashIndex(fields=["created_at"]), BTreeIndex(fields=["created_at"]), BTreeIndex(fields=["status", "created_at"]), ]
def test_deconstruction(self): index = BTreeIndex(fields=["title"], name="test_title_btree", fillfactor=80) path, args, kwargs = index.deconstruct() self.assertEqual(path, "django.contrib.postgres.indexes.BTreeIndex") self.assertEqual(args, ()) self.assertEqual( kwargs, {"fields": ["title"], "name": "test_title_btree", "fillfactor": 80} )
def test_deconstruction(self): index = BTreeIndex(fields=['title'], name='test_title_btree', fillfactor=80) path, args, kwargs = index.deconstruct() self.assertEqual(path, 'django.contrib.postgres.indexes.BTreeIndex') self.assertEqual(args, ()) self.assertEqual(kwargs, { 'fields': ['title'], 'name': 'test_title_btree', 'fillfactor': 80 })
class Meta: indexes = [ HashIndex(fields=["title"]), BTreeIndex(fields=["title", "state"]), BTreeIndex(fields=["title", "state", "delivery"]), HashIndex(fields=["state"]), HashIndex(fields=["delivery"]), HashIndex(fields=["title_slug"]), HashIndex(fields=["highlighted"]), GinIndex(fields=["tags"]), BTreeIndex(fields=["base_price"]), BTreeIndex(fields=["created_at"]), ]
class Meta: unique_together = [["product", "channel"]] ordering = ("pk",) indexes = [ models.Index(fields=["publication_date"]), BTreeIndex(fields=["discounted_price_amount"]), ]
def test_btree_parameters(self): index_name = 'integer_array_btree_fillfactor' index = BTreeIndex(fields=['field'], name=index_name, fillfactor=80) with connection.schema_editor() as editor: editor.add_index(CharFieldModel, index) constraints = self.get_constraints(CharFieldModel._meta.db_table) self.assertEqual(constraints[index_name]['type'], BTreeIndex.suffix) self.assertEqual(constraints[index_name]['options'], ['fillfactor=80']) with connection.schema_editor() as editor: editor.remove_index(CharFieldModel, index) self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
def test_btree_index(self): # Ensure the table is there and doesn't have an index. self.assertNotIn('field', self.get_constraints(CharFieldModel._meta.db_table)) # Add the index. index_name = 'char_field_model_field_btree' index = BTreeIndex(fields=['field'], name=index_name) with connection.schema_editor() as editor: editor.add_index(CharFieldModel, index) constraints = self.get_constraints(CharFieldModel._meta.db_table) # The index was added. self.assertEqual(constraints[index_name]['type'], BTreeIndex.suffix) # Drop the index. with connection.schema_editor() as editor: editor.remove_index(CharFieldModel, index) self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
def test_add_with_options(self): project_state = self.set_up_test_model(self.app_label, index=False) table_name = '%s_pony' % self.app_label new_state = project_state.clone() index = BTreeIndex(fields=['pink'], name='pony_pink_btree_idx', fillfactor=70) operation = AddIndexConcurrently('Pony', index) self.assertIndexNotExists(table_name, ['pink']) # Add index. with connection.schema_editor(atomic=False) as editor: operation.database_forwards(self.app_label, editor, project_state, new_state) self.assertIndexExists(table_name, ['pink'], index_type='btree') # Reversal. with connection.schema_editor(atomic=False) as editor: operation.database_backwards(self.app_label, editor, new_state, project_state) self.assertIndexNotExists(table_name, ['pink'])
class Meta: db_table = 'pricing_layer' verbose_name = _('pricing_layer') indexes = (BTreeIndex(fields=('name', )), )
def test_deconstruction(self): index = BTreeIndex(fields=['title'], name='test_title_btree', fillfactor=80) path, args, kwargs = index.deconstruct() self.assertEqual(path, 'django.contrib.postgres.indexes.BTreeIndex') self.assertEqual(args, ()) self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_btree', 'fillfactor': 80})
class Meta: indexes = (BTreeIndex(fields=('timestamp', )), )
class Meta: indexes = ( BTreeIndex(fields=("city_from", "city_to")), BTreeIndex(fields=("fly_from", "fly_to")), )
class Meta: indexes = [BTreeIndex(fields=["send_date"])]