|
70 | 70 | ModelWithFkToModelWithHistoryUsingBaseModelDb,
|
71 | 71 | ModelWithHistoryInDifferentDb,
|
72 | 72 | ModelWithHistoryUsingBaseModelDb,
|
| 73 | + ModelWithMultipleNoDBIndex, |
| 74 | + ModelWithSingleNoDBIndexUnique, |
73 | 75 | MultiOneToOne,
|
74 | 76 | MyOverrideModelNameRegisterMethod1,
|
75 | 77 | OverrideModelNameAsCallable,
|
@@ -1822,3 +1824,35 @@ def test_history_model_saved_in_separate_db_on_delete(self):
|
1822 | 1824 | self.assertEqual(
|
1823 | 1825 | 0, ModelWithHistoryInDifferentDb.objects.using("other").count()
|
1824 | 1826 | )
|
| 1827 | + |
| 1828 | + |
| 1829 | +class ModelWithMultipleNoDBIndexTest(TestCase): |
| 1830 | + def setUp(self): |
| 1831 | + self.model = ModelWithMultipleNoDBIndex |
| 1832 | + self.history_model = self.model.history.model |
| 1833 | + |
| 1834 | + def test_field_indices(self): |
| 1835 | + for field in ["name", "fk"]: |
| 1836 | + # dropped index |
| 1837 | + self.assertTrue(self.model._meta.get_field(field).db_index) |
| 1838 | + self.assertFalse(self.history_model._meta.get_field(field).db_index) |
| 1839 | + |
| 1840 | + # keeps index |
| 1841 | + keeps_index = "%s_keeps_index" % field |
| 1842 | + self.assertTrue(self.model._meta.get_field(keeps_index).db_index) |
| 1843 | + self.assertTrue(self.history_model._meta.get_field(keeps_index).db_index) |
| 1844 | + |
| 1845 | + |
| 1846 | +class ModelWithSingleNoDBIndexUniqueTest(TestCase): |
| 1847 | + def setUp(self): |
| 1848 | + self.model = ModelWithSingleNoDBIndexUnique |
| 1849 | + self.history_model = self.model.history.model |
| 1850 | + |
| 1851 | + def test_unique_field_index(self): |
| 1852 | + # Ending up with deferred fields (dont know why), using work around |
| 1853 | + self.assertTrue(self.model._meta.get_field("name").db_index) |
| 1854 | + self.assertFalse(self.history_model._meta.get_field("name").db_index) |
| 1855 | + |
| 1856 | + # keeps index |
| 1857 | + self.assertTrue(self.model._meta.get_field("name_keeps_index").db_index) |
| 1858 | + self.assertTrue(self.history_model._meta.get_field("name_keeps_index").db_index) |
0 commit comments