From 4a43914b9a4fab0d7b82e3d500313ddf5599c170 Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Wed, 21 Aug 2024 15:30:37 +0200 Subject: [PATCH] Replace the use of index_together --- ..._org_type_contacts_re_org_id_d53a00_idx.py | 18 ++++++++++ ureport/contacts/models.py | 2 +- ..._org_slug_landingpage_org_id_80f356_idx.py | 18 ++++++++++ ureport/landingpages/models.py | 4 ++- ...me_osm_id_locations_b_org_id_ee9365_idx.py | 18 ++++++++++ ureport/locations/models.py | 4 ++- ...d_polls_poll_org_id_3461d6_idx_and_more.py | 33 +++++++++++++++++++ ureport/polls/models.py | 13 ++++++-- ..._stats_conta_org_id_296d47_idx_and_more.py | 23 +++++++++++++ ureport/stats/models.py | 5 ++- 10 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 ureport/contacts/migrations/0028_rename_reporterscounter_org_type_contacts_re_org_id_d53a00_idx.py create mode 100644 ureport/landingpages/migrations/0005_rename_landingpage_org_slug_landingpage_org_id_80f356_idx.py create mode 100644 ureport/locations/migrations/0008_rename_boundary_org_level_name_osm_id_locations_b_org_id_ee9365_idx.py create mode 100644 ureport/polls/migrations/0077_rename_poll_org_published_id_polls_poll_org_id_3461d6_idx_and_more.py create mode 100644 ureport/stats/migrations/0029_rename_contactactivity_org_date_stats_conta_org_id_296d47_idx_and_more.py diff --git a/ureport/contacts/migrations/0028_rename_reporterscounter_org_type_contacts_re_org_id_d53a00_idx.py b/ureport/contacts/migrations/0028_rename_reporterscounter_org_type_contacts_re_org_id_d53a00_idx.py new file mode 100644 index 000000000..67ebe55b4 --- /dev/null +++ b/ureport/contacts/migrations/0028_rename_reporterscounter_org_type_contacts_re_org_id_d53a00_idx.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.8 on 2024-08-21 12:10 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("contacts", "0027_install_triggers"), + ] + + operations = [ + migrations.RenameIndex( + model_name="reporterscounter", + new_name="contacts_re_org_id_d53a00_idx", + old_fields=("org", "type"), + ), + ] diff --git a/ureport/contacts/models.py b/ureport/contacts/models.py index c23d85320..29a990098 100644 --- a/ureport/contacts/models.py +++ b/ureport/contacts/models.py @@ -320,7 +320,7 @@ def get_counts(cls, org, types=None): return {c["type"]: c["count_sum"] for c in counter_counts} class Meta: - index_together = ("org", "type") indexes = [ models.Index(name="contacts_rptrscntr_org_typ_cnt", fields=["org", "type", "count"]), + models.Index(name=None, fields=["org", "type"]), ] diff --git a/ureport/landingpages/migrations/0005_rename_landingpage_org_slug_landingpage_org_id_80f356_idx.py b/ureport/landingpages/migrations/0005_rename_landingpage_org_slug_landingpage_org_id_80f356_idx.py new file mode 100644 index 000000000..8de10ac63 --- /dev/null +++ b/ureport/landingpages/migrations/0005_rename_landingpage_org_slug_landingpage_org_id_80f356_idx.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.8 on 2024-08-21 12:10 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("landingpages", "0004_alter_landingpage_created_by_and_more"), + ] + + operations = [ + migrations.RenameIndex( + model_name="landingpage", + new_name="landingpage_org_id_80f356_idx", + old_fields=("org", "slug"), + ), + ] diff --git a/ureport/landingpages/models.py b/ureport/landingpages/models.py index 35e029876..1f23d08f8 100644 --- a/ureport/landingpages/models.py +++ b/ureport/landingpages/models.py @@ -37,7 +37,9 @@ class LandingPage(SmartModel): bots = models.ManyToManyField(Bot, blank=True) class Meta: - index_together = (("org", "slug"),) + indexes = [ + models.Index(name=None, fields=["org", "slug"]), + ] constraints = [ models.UniqueConstraint(fields=["org", "slug"], name="landingpages_landingpage_org_id_slug_f7f1304e_uniq") ] diff --git a/ureport/locations/migrations/0008_rename_boundary_org_level_name_osm_id_locations_b_org_id_ee9365_idx.py b/ureport/locations/migrations/0008_rename_boundary_org_level_name_osm_id_locations_b_org_id_ee9365_idx.py new file mode 100644 index 000000000..f82357998 --- /dev/null +++ b/ureport/locations/migrations/0008_rename_boundary_org_level_name_osm_id_locations_b_org_id_ee9365_idx.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.8 on 2024-08-21 12:10 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("locations", "0007_alter_boundary_index_together"), + ] + + operations = [ + migrations.RenameIndex( + model_name="boundary", + new_name="locations_b_org_id_ee9365_idx", + old_fields=("org", "level", "name", "osm_id"), + ), + ] diff --git a/ureport/locations/models.py b/ureport/locations/models.py index 9792f89a3..94f4891ff 100644 --- a/ureport/locations/models.py +++ b/ureport/locations/models.py @@ -55,7 +55,9 @@ class Meta: constraints = [ models.UniqueConstraint(fields=["org", "osm_id"], name="locations_boundary_org_id_5c2d99160b82334a_uniq") ] - index_together = ("org", "level", "name", "osm_id") + indexes = [ + models.Index(name=None, fields=["org", "level", "name", "osm_id"]), + ] @classmethod def lock(cls, org, osm_id): diff --git a/ureport/polls/migrations/0077_rename_poll_org_published_id_polls_poll_org_id_3461d6_idx_and_more.py b/ureport/polls/migrations/0077_rename_poll_org_published_id_polls_poll_org_id_3461d6_idx_and_more.py new file mode 100644 index 000000000..c4d344ea2 --- /dev/null +++ b/ureport/polls/migrations/0077_rename_poll_org_published_id_polls_poll_org_id_3461d6_idx_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 5.0.8 on 2024-08-21 12:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("polls", "0076_alter_poll_index_together"), + ] + + operations = [ + migrations.RenameIndex( + model_name="poll", + new_name="polls_poll_org_id_3461d6_idx", + old_fields=("org", "published", "id"), + ), + migrations.RenameIndex( + model_name="pollquestion", + new_name="polls_pollq_poll_id_68485b_idx", + old_fields=("poll", "is_active", "flow_result"), + ), + migrations.RenameIndex( + model_name="pollresult", + new_name="polls_pollr_org_id_428d8a_idx", + old_fields=("org", "flow", "ruleset", "text"), + ), + migrations.RenameIndex( + model_name="pollresult", + new_name="polls_pollr_org_id_0f793f_idx", + old_fields=("org", "flow"), + ), + ] diff --git a/ureport/polls/models.py b/ureport/polls/models.py index 6b3b2a867..d1ad6e52b 100644 --- a/ureport/polls/models.py +++ b/ureport/polls/models.py @@ -737,7 +737,9 @@ def __str__(self): return self.title class Meta: - index_together = ("org", "published", "id") + indexes = [ + models.Index(name=None, fields=["org", "published", "id"]), + ] @six.python_2_unicode_compatible @@ -1302,7 +1304,9 @@ class Meta: fields=["poll", "flow_result"], name="polls_pollquestion_poll_id_flow_result_id_608a2446_uniq" ), ] - index_together = ("poll", "is_active", "flow_result") + indexes = [ + models.Index(name=None, fields=["poll", "is_active", "flow_result"]), + ] class PollResponseCategory(models.Model): @@ -1451,4 +1455,7 @@ def generate_poll_stats(self): return generated_stats class Meta: - index_together = [["org", "flow"], ["org", "flow", "ruleset", "text"]] + indexes = [ + models.Index(name=None, fields=["org", "flow"]), + models.Index(name=None, fields=["org", "flow", "ruleset", "text"]), + ] diff --git a/ureport/stats/migrations/0029_rename_contactactivity_org_date_stats_conta_org_id_296d47_idx_and_more.py b/ureport/stats/migrations/0029_rename_contactactivity_org_date_stats_conta_org_id_296d47_idx_and_more.py new file mode 100644 index 000000000..1fc1cb6f2 --- /dev/null +++ b/ureport/stats/migrations/0029_rename_contactactivity_org_date_stats_conta_org_id_296d47_idx_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.8 on 2024-08-21 12:10 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("stats", "0028_activities_counter_triggers"), + ] + + operations = [ + migrations.RenameIndex( + model_name="contactactivity", + new_name="stats_conta_org_id_296d47_idx", + old_fields=("org", "date"), + ), + migrations.RenameIndex( + model_name="contactactivity", + new_name="stats_conta_org_id_e76e89_idx", + old_fields=("org", "contact"), + ), + ] diff --git a/ureport/stats/models.py b/ureport/stats/models.py index 890cdbb63..59de6cef0 100644 --- a/ureport/stats/models.py +++ b/ureport/stats/models.py @@ -736,7 +736,10 @@ class ContactActivity(models.Model): used = models.BooleanField(null=True) class Meta: - index_together = (("org", "contact"), ("org", "date")) + indexes = [ + models.Index(name=None, fields=["org", "contact"]), + models.Index(name=None, fields=["org", "date"]), + ] constraints = [ models.UniqueConstraint( fields=["org", "contact", "date"], name="stats_contactactivity_org_id_contact_date_348227aa_uniq"