(self)
| 516 | |
| 517 | @skipUnlessDBFeature("supports_expression_indexes") |
| 518 | def test_partial_func_index(self): |
| 519 | index_name = "partial_func_idx" |
| 520 | index = Index( |
| 521 | Lower("headline").desc(), |
| 522 | name=index_name, |
| 523 | condition=Q(pub_date__isnull=False), |
| 524 | ) |
| 525 | with connection.schema_editor() as editor: |
| 526 | editor.add_index(index=index, model=Article) |
| 527 | sql = index.create_sql(Article, schema_editor=editor) |
| 528 | table = Article._meta.db_table |
| 529 | self.assertIs(sql.references_column(table, "headline"), True) |
| 530 | sql = str(sql) |
| 531 | self.assertIn("LOWER(%s)" % editor.quote_name("headline"), sql) |
| 532 | self.assertIn( |
| 533 | "WHERE %s IS NOT NULL" % editor.quote_name("pub_date"), |
| 534 | sql, |
| 535 | ) |
| 536 | self.assertGreater(sql.find("WHERE"), sql.find("LOWER")) |
| 537 | with connection.cursor() as cursor: |
| 538 | constraints = connection.introspection.get_constraints( |
| 539 | cursor=cursor, |
| 540 | table_name=table, |
| 541 | ) |
| 542 | self.assertIn(index_name, constraints) |
| 543 | if connection.features.supports_index_column_ordering: |
| 544 | self.assertEqual(constraints[index_name]["orders"], ["DESC"]) |
| 545 | with connection.schema_editor() as editor: |
| 546 | editor.remove_index(Article, index) |
| 547 | with connection.cursor() as cursor: |
| 548 | self.assertNotIn( |
| 549 | index_name, |
| 550 | connection.introspection.get_constraints( |
| 551 | cursor=cursor, |
| 552 | table_name=table, |
| 553 | ), |
| 554 | ) |
| 555 | |
| 556 | |
| 557 | @skipUnlessDBFeature("supports_covering_indexes") |
nothing calls this directly
no test coverage detected