def test_deconstruction_no_customization(self): index = GistIndex(fields=['title'], name='test_title_gist') path, args, kwargs = index.deconstruct() self.assertEqual(path, 'django.contrib.postgres.indexes.GistIndex') self.assertEqual(args, ()) self.assertEqual(kwargs, { 'fields': ['title'], 'name': 'test_title_gist' })
def test_deconstruction(self): index = GistIndex(fields=['title'], name='test_title_gist', buffering=False, fillfactor=80) path, args, kwargs = index.deconstruct() self.assertEqual(path, 'django.contrib.postgres.indexes.GistIndex') self.assertEqual(args, ()) self.assertEqual(kwargs, { 'fields': ['title'], 'name': 'test_title_gist', 'buffering': False, 'fillfactor': 80, })
def test_deconstruction(self): index = GistIndex(fields=['title'], name='test_title_gist', buffering=False, fillfactor=80) path, args, kwargs = index.deconstruct() self.assertEqual(path, 'django.contrib.postgres.indexes.GistIndex') self.assertEqual(args, ()) self.assertEqual(kwargs, { 'fields': ['title'], 'name': 'test_title_gist', 'buffering': False, 'fillfactor': 80, })
class Meta: ordering = ['-id'] indexes = [ GistIndex(name='branch_name_gist_trgm_index', fields=['name'], opclasses=['gist_trgm_ops']), ]
class Meta: indexes = ( GistIndex( fields=('source_ip',), opclasses=('inet_ops',), name='dmarc_record_source_ip_idx' ), )
def test_deconstruction(self): index = GistIndex( fields=["title"], name="test_title_gist", buffering=False, fillfactor=80 ) path, args, kwargs = index.deconstruct() self.assertEqual(path, "django.contrib.postgres.indexes.GistIndex") self.assertEqual(args, ()) self.assertEqual( kwargs, { "fields": ["title"], "name": "test_title_gist", "buffering": False, "fillfactor": 80, }, )
class Meta: abstract = True indexes = [ Index(fields=['ltree_label_path']), GistIndex(fields=['ltree_label_path']), LTreeIndex(fields=['ltree_label_path']), ]
class Meta: unique_together = ('ip_address', 'stream', 'session', 'user_agent') ordering = ('-session', ) indexes = [ GistIndex(fields=[ 'session', ]), ]
class Meta: ordering = ['id'] indexes = [ models.Index(fields=[ 'identifier', ]), GistIndex(fields=['layer', 'geom']), ]
class Meta: verbose_name = 'Диапазон телефонных номеров' verbose_name_plural = 'Диапазоны телефонных номеров' required_db_vendor = 'postgresql' indexes = (GistIndex( fields=( 'abc_or_def', 'numbers_range', ), fillfactor=100, ), )
def test_gist_parameters(self): index_name = 'integer_array_gist_buffering' index = GistIndex(fields=['field'], name=index_name, buffering=True, 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'], GistIndex.suffix) self.assertEqual(constraints[index_name]['options'], ['buffering=on', '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_gist_include(self): index_name = "scene_gist_include_setting" index = GistIndex(name=index_name, fields=["scene"], include=["setting"]) with connection.schema_editor() as editor: editor.add_index(Scene, index) constraints = self.get_constraints(Scene._meta.db_table) self.assertIn(index_name, constraints) self.assertEqual(constraints[index_name]["type"], GistIndex.suffix) self.assertEqual(constraints[index_name]["columns"], ["scene", "setting"]) with connection.schema_editor() as editor: editor.remove_index(Scene, index) self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
def test_tsvector_op_class_gist_index(self): index_name = "tsvector_op_class_gist" index = GistIndex( OpClass( SearchVector("scene", "setting", config="english"), name="tsvector_ops", ), name=index_name, ) with connection.schema_editor() as editor: editor.add_index(Scene, index) sql = index.create_sql(Scene, editor) table = Scene._meta.db_table constraints = self.get_constraints(table) self.assertIn(index_name, constraints) self.assertIn(constraints[index_name]["type"], GistIndex.suffix) self.assertIs(sql.references_column(table, "scene"), True) self.assertIs(sql.references_column(table, "setting"), True) with connection.schema_editor() as editor: editor.remove_index(Scene, index) self.assertNotIn(index_name, self.get_constraints(table))
def test_gist_include_not_supported(self): index_name = "gist_include_exception" index = GistIndex(fields=["scene"], name=index_name, include=["setting"]) msg = "Covering GiST indexes require PostgreSQL 12+." with self.assertRaisesMessage(NotSupportedError, msg): with mock.patch( "django.db.backends.postgresql.features.DatabaseFeatures." "supports_covering_gist_indexes", False, ): with connection.schema_editor() as editor: editor.add_index(Scene, index) self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
def test_gist_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_gist' index = GistIndex(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'], GistIndex.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))
class Meta: unique_together = ( ('feature', 'layer_extra_geom'), ) indexes = [ models.Index(fields=['layer_extra_geom', 'identifier']), GistIndex(name='feg_geom_gist_index', fields=['layer_extra_geom', 'geom']), GinIndex(name='feg_properties_gin_index', fields=['properties']), ] constraints = [ # geometry should be valid models.CheckConstraint(check=models.Q(geom__isvalid=True), name='geom_extra_is_valid'), # geometry should not be empty models.CheckConstraint(check=models.Q(geom__isempty=False), name='geom_extra_is_empty') ]
class Meta: verbose_name = "Dashboard index" verbose_name_plural = "Dashboard indexes" ordering = ("label", ) indexes = [ GinIndex( name="ext_dashboard_index_gin_idx", fields=["search"], opclasses=["gin_trgm_ops"], ), GistIndex( name="ext_dashboard_index_gist_idx", fields=["search"], opclasses=["gist_trgm_ops"], ), ]
class Meta: verbose_name = "Catalog index" verbose_name_plural = "Catalog indexes" ordering = ("external_name", ) indexes = [ GinIndex( name="catalog_index_search_gin_idx", fields=["search"], opclasses=["gin_trgm_ops"], ), GistIndex( name="catalog_index_search_gist_idx", fields=["search"], opclasses=["gist_trgm_ops"], ), ]
class Meta: abstract = True ordering = ['path'] constraints = [ # We want this deferred, because sometimes we move more than one node at once # and there might be an intermediate step where nodes conflict models.UniqueConstraint( name='%(app_label)s_%(class)s_unique_path_deferred', fields=['path'], deferrable=models.Deferrable.DEFERRED, ) ] indexes = [ # This would probably be better served as # the default if Ltree(index=True) is specified GistIndex( fields=['path'] ), ]
class Meta: ordering = ['id'] indexes = [ models.Index(fields=['layer', ]), models.Index(fields=['updated_at', ]), models.Index(fields=['updated_at', 'layer', ]), models.Index(fields=['layer', 'identifier']), models.Index(fields=['id', 'layer', ]), models.Index(fields=['source', 'layer', ]), models.Index(fields=['target', 'layer', ]), models.Index(fields=['source', 'target', 'layer']), GistIndex(fields=['layer', 'geom']), GinIndex(name='properties_gin_index', fields=['properties']), ] constraints = [ # geometry should be valid models.CheckConstraint(check=models.Q(geom__isvalid=True), name='geom_is_valid'), # geometry should not be empty models.CheckConstraint(check=models.Q(geom__isempty=False), name='geom_is_empty') ]
class Meta: abstract = True indexes = (GistIndex(fields=["tree_path"], name="tree_path_idx"),) ordering = ("tree_path",)
def test_name_auto_generation(self): index = GistIndex(fields=['field']) index.set_name_with_model(CharFieldModel) self.assertEqual(index.name, 'postgres_te_field_1e0206_gist')
class Meta(BaseModel.Meta): verbose_name = _('Period') verbose_name_plural = _('Periods') indexes = [GistIndex(fields=['period'])]
class Meta: indexes = [GistIndex(fields=["path"], buffering=True)]
def test_name_auto_generation(self): index = GistIndex(fields=['field']) index.set_name_with_model(CharFieldModel) self.assertEqual(index.name, 'postgres_te_field_1e0206_gist')
class Meta: verbose_name_plural = "Search All Product Keywords" indexes = [GistIndex(fields=["keywords"])]
def test_deconstruction_no_customization(self): index = GistIndex(fields=['title'], name='test_title_gist') path, args, kwargs = index.deconstruct() self.assertEqual(path, 'django.contrib.postgres.indexes.GistIndex') self.assertEqual(args, ()) self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_gist'})
def test_eq(self): index = GistIndex(fields=['title'], fillfactor=64) same_index = GistIndex(fields=['title'], fillfactor=64) another_index = GistIndex(fields=['author'], buffering=True) self.assertEqual(index, same_index) self.assertNotEqual(index, another_index)