class Meta: indexes = [ PartialIndex(fields=['-order'], unique=False, where=PQ(is_complete=False)), PartialIndex(fields=['group'], unique=True, where=PQ(is_complete=False)), ]
class Meta: db_table = "recipient_lookup" indexes = [ PartialIndex(fields=["duns"], unique=True, where=PQ(duns__isnull=False)), PartialIndex(fields=["parent_duns"], unique=False, where=PQ(parent_duns__isnull=False)), ]
class Meta: indexes = [ PartialIndex(fields=['room', 'label'], unique=True, where=PQ(deleted_at__isnull=True)), PartialIndex(fields=['user', 'label'], unique=True, where=PQ(deleted_at__isnull=True)), PartialIndex(fields=['uuid'], unique=True, where=PQ(deleted_at__isnull=True)), ] unique_together = [['room', 'user']] # Regardless of deletion status
def test_deconstruct_pq(self): path, args, kwargs = self.idx.deconstruct() self.assertEqual(path, 'partial_index.PartialIndex') self.assertEqual((), args) self.assertEqual(kwargs['fields'], ['a', 'b']) self.assertEqual(kwargs['unique'], True) self.assertEqual(kwargs['where'], PQ(a__isnull=True)) self.assertNotIn('where_postgresql', kwargs) self.assertNotIn('where_sqlite', kwargs) self.assertIn('name', kwargs) # Exact value of name is not tested.
def test_not_unique_q(self): index_name = 'jobq_test_idx' index = PartialIndex(fields=['-group'], name=index_name, unique=False, where=PQ(is_complete=False)) self.assertAddRemoveConstraint(JobQ, index_name, index, { 'columns': ['group'], 'orders': ['DESC'], 'primary_key': False, 'check': False, 'index': True, 'unique': False, })
class Meta: unique_together = [ # HACK work around unique=True implies db_index=True # https://code.djangoproject.com/ticket/24082 # Avoid extra varchar_pattern_ops index # since we do not do LIKE queries on these # https://stackoverflow.com/a/50926644/10840 ("key",), ] index_together = [("parent_id", "type_code", "name")] indexes = [ PartialIndex( fields=['expires_on'], unique=False, where=PQ(expires_on__isnull=False), ), PartialIndex( fields=['type_code', 'created_on'], unique=False, where=PQ(domain='icds-cas'), ), ]
class Meta: indexes = [ PartialIndex(fields=["facility", "room_type"], unique=True, where=PQ(deleted=False)) ]
def test_single_null(self): self.assertMentioned(PQ(a__isnull=True), ['a']) self.assertMentioned(PQ(a__isnull=False), ['a'])
class Meta: indexes = [ PartialIndex(fields=['a', 'b'], unique=True, where=PQ(a=PF('b'))), ]
def test_where_changes_generated_name(self): idx1 = PartialIndex(fields=['a', 'b'], unique=False, where=PQ(a__isnull=True)) idx1.set_name_with_model(AB) idx2 = PartialIndex(fields=['a', 'b'], unique=False, where=PQ(a__isnull=False)) idx2.set_name_with_model(AB) self.assertNotEqual(idx1.name, idx2.name)
def test_f_add(self): self.assertMentioned(PQ(a=PF('b') + PF('c') + 1), ['a', 'b', 'c'])
def test_fields(self): self.assertEqual(self.idx.unique, True) self.assertEqual(self.idx.where, PQ(a__isnull=True)) self.assertEqual(self.idx.where_postgresql, '') self.assertEqual(self.idx.where_sqlite, '')
def test_generated_name_ends_with_partial(self): idx = PartialIndex(fields=['a', 'b'], unique=False, where=PQ(a__isnull=True)) idx.set_name_with_model(AB) self.assertEqual(idx.name[-8:], '_partial')
def test_two_null(self): self.assertMentioned(PQ(a=12, b__isnull=True), ['a', 'b'])
class Meta: indexes = [ PartialIndex(fields=["patient", "disease"], unique=True, where=PQ(deleted=False)) ]
def test_or_extra(self): self.assertMentioned(PQ(a=12, b=34) | PQ(c=56), ['a', 'b', 'c'])
def test_unique_q(self): index_name = 'roombookingq_test_idx' index = PartialIndex(fields=['user', 'room'], name=index_name, unique=True, where=PQ(deleted_at__isnull=True)) self.assertAddRemoveConstraint(RoomBookingQ, index_name, index, { 'columns': ['user_id', 'room_id'], 'primary_key': False, 'check': False, 'index': True, 'unique': True, })
def test_or_duplicate(self): self.assertMentioned(PQ(a=12, b=34) | PQ(b=56), ['a', 'b'])
def test_or(self): self.assertMentioned(PQ(a=12) | PQ(b=34), ['a', 'b'])
def test_contains_f(self): self.assertMentioned(PQ(a__contains='Hello', b=PF('c')), ['a', 'b', 'c'])
def setUp(self): self.idx = PartialIndex(fields=['a', 'b'], unique=True, where=PQ(a__isnull=True))
def test_two_const(self): self.assertMentioned(PQ(a=12, b=34), ['a', 'b'])
def test_no_unique(self): with self.assertRaisesMessage(ValueError, 'Unique must be True or False'): PartialIndex(fields=['a', 'b'], where=PQ(a__isnull=True))
class Meta: indexes = [ PartialIndex(fields=['user', 'company'], unique=True, where=PQ(status=common_constant.USER_STATUS.ACTIVE)) ]
def test_single_const_exact(self): self.assertMentioned(PQ(a__exact=123), ['a'])
class Meta: indexes = [ PartialIndex(fields=['employee', 'workflow'], unique=True, where=PQ(is_active=True)) ]
def test_same_args_same_name(self): idx1 = PartialIndex(fields=['a', 'b'], unique=False, where=PQ(a__isnull=True)) idx1.set_name_with_model(AB) idx2 = PartialIndex(fields=['a', 'b'], unique=False, where=PQ(a__isnull=True)) idx2.set_name_with_model(AB) self.assertEqual(idx1.name, idx2.name)
class Meta: indexes = [ PartialIndex(fields=['user', 'room'], unique=True, where=PQ(deleted_at__isnull=True)) ]
def test_single_q_and_pg_and_sqlite(self): with self.assertRaisesRegexp(ValueError, 'must not provide'): PartialIndex(fields=['a', 'b'], unique=True, where=PQ(a__isnull=True), where_postgresql='a IS NULL', where_sqlite='a IS NULL')
def test_f_equal(self): self.assertMentioned(PQ(a=PF('b')), ['a', 'b'])