diff --git a/ureport/contacts/migrations/0028_rename_reporterscounter_org_type_contacts_rptrscntr_org_id_idx_and_more.py b/ureport/contacts/migrations/0028_rename_reporterscounter_org_type_contacts_rptrscntr_org_id_idx_and_more.py new file mode 100644 index 000000000..48fac7abc --- /dev/null +++ b/ureport/contacts/migrations/0028_rename_reporterscounter_org_type_contacts_rptrscntr_org_id_idx_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 5.0.8 on 2024-08-23 13:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("contacts", "0027_install_triggers"), + ("orgs", "0033_rename_orgs_orgbac_org_id_607508_idx_orgs_orgbac_org_slug_idx_and_more"), + ] + + operations = [ + migrations.RenameIndex( + model_name="reporterscounter", + new_name="contacts_rptrscntr_org_id_idx", + old_fields=("org", "type"), + ), + migrations.AlterUniqueTogether( + name="contact", + unique_together=set(), + ), + migrations.AddConstraint( + model_name="contact", + constraint=models.UniqueConstraint( + fields=("org", "uuid"), name="contacts_contact_org_id_563dcefdcba190b9_uniq" + ), + ), + ] diff --git a/ureport/contacts/models.py b/ureport/contacts/models.py index ed30f9a8e..6b810b35f 100644 --- a/ureport/contacts/models.py +++ b/ureport/contacts/models.py @@ -231,7 +231,9 @@ def generate_counters(self): return generated_counters class Meta: - unique_together = ("org", "uuid") + constraints = [ + models.UniqueConstraint(fields=["org", "uuid"], name="contacts_contact_org_id_563dcefdcba190b9_uniq") + ] class ReportersCounter(models.Model): @@ -318,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_id_idx", fields=["org", "type"]), models.Index(name="contacts_rptrscntr_org_typ_cnt", fields=["org", "type", "count"]), ] diff --git a/ureport/flows/migrations/0002_alter_flowresult_unique_together_and_more.py b/ureport/flows/migrations/0002_alter_flowresult_unique_together_and_more.py new file mode 100644 index 000000000..df6df3178 --- /dev/null +++ b/ureport/flows/migrations/0002_alter_flowresult_unique_together_and_more.py @@ -0,0 +1,25 @@ +# Generated by Django 5.0.8 on 2024-08-23 13:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("flows", "0001_initial"), + ("orgs", "0033_rename_orgs_orgbac_org_id_607508_idx_orgs_orgbac_org_slug_idx_and_more"), + ] + + operations = [ + migrations.AlterUniqueTogether( + name="flowresult", + unique_together=set(), + ), + migrations.AddConstraint( + model_name="flowresult", + constraint=models.UniqueConstraint( + fields=("org", "flow_uuid", "result_uuid"), + name="flows_flowresult_org_id_flow_uuid_result_uuid_5efa8f2d_uniq", + ), + ), + ] diff --git a/ureport/flows/models.py b/ureport/flows/models.py index 8af041245..e380ad86a 100644 --- a/ureport/flows/models.py +++ b/ureport/flows/models.py @@ -31,7 +31,12 @@ def update_or_create(cls, org, flow_uuid, result_uuid, result_name): return obj class Meta: - unique_together = ("org", "flow_uuid", "result_uuid") + constraints = [ + models.UniqueConstraint( + fields=["org", "flow_uuid", "result_uuid"], + name="flows_flowresult_org_id_flow_uuid_result_uuid_5efa8f2d_uniq", + ) + ] class FlowResultCategory(models.Model): diff --git a/ureport/landingpages/migrations/0005_alter_landingpage_unique_together_and_more.py b/ureport/landingpages/migrations/0005_alter_landingpage_unique_together_and_more.py new file mode 100644 index 000000000..4ce76df2a --- /dev/null +++ b/ureport/landingpages/migrations/0005_alter_landingpage_unique_together_and_more.py @@ -0,0 +1,31 @@ +# Generated by Django 5.0.8 on 2024-08-23 13:00 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bots", "0006_alter_bot_created_by_alter_bot_modified_by"), + ("landingpages", "0004_alter_landingpage_created_by_and_more"), + ("orgs", "0033_rename_orgs_orgbac_org_id_607508_idx_orgs_orgbac_org_slug_idx_and_more"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AlterUniqueTogether( + name="landingpage", + unique_together=set(), + ), + migrations.AlterIndexTogether( + name="landingpage", + index_together=set(), + ), + migrations.AddConstraint( + model_name="landingpage", + constraint=models.UniqueConstraint( + fields=("org", "slug"), name="landingpages_landingpage_org_id_slug_f7f1304e_uniq" + ), + ), + ] diff --git a/ureport/landingpages/models.py b/ureport/landingpages/models.py index 404d100d8..5c03dad5f 100644 --- a/ureport/landingpages/models.py +++ b/ureport/landingpages/models.py @@ -37,5 +37,6 @@ class LandingPage(SmartModel): bots = models.ManyToManyField(Bot, blank=True) class Meta: - index_together = (("org", "slug"),) - unique_together = ("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_bd_org_lv_nm_osm_idx_and_more.py b/ureport/locations/migrations/0008_rename_boundary_org_level_name_osm_id_locations_bd_org_lv_nm_osm_idx_and_more.py new file mode 100644 index 000000000..9ad99ff09 --- /dev/null +++ b/ureport/locations/migrations/0008_rename_boundary_org_level_name_osm_id_locations_bd_org_lv_nm_osm_idx_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 5.0.8 on 2024-08-23 13:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("locations", "0007_alter_boundary_index_together"), + ("orgs", "0033_rename_orgs_orgbac_org_id_607508_idx_orgs_orgbac_org_slug_idx_and_more"), + ] + + operations = [ + migrations.RenameIndex( + model_name="boundary", + new_name="locations_bd_org_lv_nm_osm_idx", + old_fields=("org", "level", "name", "osm_id"), + ), + migrations.AlterUniqueTogether( + name="boundary", + unique_together=set(), + ), + migrations.AddConstraint( + model_name="boundary", + constraint=models.UniqueConstraint( + fields=("org", "osm_id"), name="locations_boundary_org_id_5c2d99160b82334a_uniq" + ), + ), + ] diff --git a/ureport/locations/models.py b/ureport/locations/models.py index 15be8c82f..fb32124b2 100644 --- a/ureport/locations/models.py +++ b/ureport/locations/models.py @@ -52,8 +52,12 @@ class Boundary(models.Model): ) class Meta: - unique_together = ("org", "osm_id") - index_together = ("org", "level", "name", "osm_id") + constraints = [ + models.UniqueConstraint(fields=["org", "osm_id"], name="locations_boundary_org_id_5c2d99160b82334a_uniq") + ] + indexes = [ + models.Index(fields=["org", "level", "name", "osm_id"], name="locations_bd_org_lv_nm_osm_idx"), + ] @classmethod def lock(cls, org, osm_id): diff --git a/ureport/polls/migrations/0077_rename_poll_org_published_id_polls_poll_org_pblshd_id_idx_and_more.py b/ureport/polls/migrations/0077_rename_poll_org_published_id_polls_poll_org_pblshd_id_idx_and_more.py new file mode 100644 index 000000000..8a37d9195 --- /dev/null +++ b/ureport/polls/migrations/0077_rename_poll_org_published_id_polls_poll_org_pblshd_id_idx_and_more.py @@ -0,0 +1,80 @@ +# Generated by Django 5.0.8 on 2024-08-23 13:00 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("flows", "0002_alter_flowresult_unique_together_and_more"), + ("orgs", "0033_rename_orgs_orgbac_org_id_607508_idx_orgs_orgbac_org_slug_idx_and_more"), + ("polls", "0076_alter_poll_index_together"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.RenameIndex( + model_name="poll", + new_name="polls_poll_org_pblshd_id_idx", + old_fields=("org", "published", "id"), + ), + migrations.RenameIndex( + model_name="pollquestion", + new_name="polls_qstn_poll_actv_fl_rs_idx", + old_fields=("poll", "is_active", "flow_result"), + ), + migrations.RenameIndex( + model_name="pollresult", + new_name="polls_rslt_org_flw_rst_txt_idx", + old_fields=("org", "flow", "ruleset", "text"), + ), + migrations.RenameIndex( + model_name="pollresult", + new_name="polls_pollresult_org_flow_idx", + old_fields=("org", "flow"), + ), + migrations.AlterUniqueTogether( + name="pollcategory", + unique_together=set(), + ), + migrations.AlterUniqueTogether( + name="pollquestion", + unique_together=set(), + ), + migrations.AlterUniqueTogether( + name="pollresponsecategory", + unique_together=set(), + ), + migrations.AddConstraint( + model_name="pollcategory", + constraint=models.UniqueConstraint( + fields=("name", "org"), name="polls_pollcategory_name_156693e034f96627_uniq" + ), + ), + migrations.AddConstraint( + model_name="pollquestion", + constraint=models.UniqueConstraint( + fields=("poll", "flow_result"), name="polls_pollquestion_poll_id_flow_result_id_608a2446_uniq" + ), + ), + migrations.AddConstraint( + model_name="pollquestion", + constraint=models.UniqueConstraint( + fields=("poll", "ruleset_uuid"), name="polls_pollquestion_poll_id_4202706c8106f06_uniq" + ), + ), + migrations.AddConstraint( + model_name="pollresponsecategory", + constraint=models.UniqueConstraint( + fields=("question", "rule_uuid"), name="polls_pollresponsecategory_question_id_3a161715511bd77d_uniq" + ), + ), + migrations.AddConstraint( + model_name="pollresponsecategory", + constraint=models.UniqueConstraint( + fields=("question", "flow_result_category"), + name="polls_pollresponsecatego_question_id_flow_result__4db1cb7e_uniq", + ), + ), + ] diff --git a/ureport/polls/models.py b/ureport/polls/models.py index 11c426cb3..1a1196bb5 100644 --- a/ureport/polls/models.py +++ b/ureport/polls/models.py @@ -74,7 +74,9 @@ def __str__(self): return self.name class Meta: - unique_together = ("name", "org") + constraints = [ + models.UniqueConstraint(fields=["name", "org"], name="polls_pollcategory_name_156693e034f96627_uniq") + ] verbose_name_plural = _("Poll Categories") @@ -735,7 +737,9 @@ def __str__(self): return self.title class Meta: - index_together = ("org", "published", "id") + indexes = [ + models.Index(fields=["org", "published", "id"], name="polls_poll_org_pblshd_id_idx"), + ] @six.python_2_unicode_compatible @@ -1292,8 +1296,17 @@ def __str__(self): return self.title class Meta: - unique_together = (("poll", "ruleset_uuid"), ("poll", "flow_result")) - index_together = ("poll", "is_active", "flow_result") + indexes = [ + models.Index(fields=["poll", "is_active", "flow_result"], name="polls_qstn_poll_actv_fl_rs_idx"), + ] + constraints = [ + models.UniqueConstraint( + fields=["poll", "flow_result"], name="polls_pollquestion_poll_id_flow_result_id_608a2446_uniq" + ), + models.UniqueConstraint( + fields=["poll", "ruleset_uuid"], name="polls_pollquestion_poll_id_4202706c8106f06_uniq" + ), + ] class PollResponseCategory(models.Model): @@ -1338,7 +1351,15 @@ def update_or_create(cls, question, rule_uuid, category): return existing class Meta: - unique_together = (("question", "rule_uuid"), ("question", "flow_result_category")) + constraints = [ + models.UniqueConstraint( + fields=["question", "rule_uuid"], name="polls_pollresponsecategory_question_id_3a161715511bd77d_uniq" + ), + models.UniqueConstraint( + fields=["question", "flow_result_category"], + name="polls_pollresponsecatego_question_id_flow_result__4db1cb7e_uniq", + ), + ] class PollResult(models.Model): @@ -1434,4 +1455,7 @@ def generate_poll_stats(self): return generated_stats class Meta: - index_together = [["org", "flow"], ["org", "flow", "ruleset", "text"]] + indexes = [ + models.Index(fields=["org", "flow"], name="polls_pollresult_org_flow_idx"), + models.Index(fields=["org", "flow", "ruleset", "text"], name="polls_rslt_org_flw_rst_txt_idx"), + ] diff --git a/ureport/stats/migrations/0029_rename_contactactivity_org_contact_stats_ct_actvt_org_contact_idx_and_more.py b/ureport/stats/migrations/0029_rename_contactactivity_org_contact_stats_ct_actvt_org_contact_idx_and_more.py new file mode 100644 index 000000000..c89172093 --- /dev/null +++ b/ureport/stats/migrations/0029_rename_contactactivity_org_contact_stats_ct_actvt_org_contact_idx_and_more.py @@ -0,0 +1,34 @@ +# Generated by Django 5.0.8 on 2024-08-23 13:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("orgs", "0033_rename_orgs_orgbac_org_id_607508_idx_orgs_orgbac_org_slug_idx_and_more"), + ("stats", "0028_activities_counter_triggers"), + ] + + operations = [ + migrations.RenameIndex( + model_name="contactactivity", + new_name="stats_ct_actvt_org_contact_idx", + old_fields=("org", "contact"), + ), + migrations.RenameIndex( + model_name="contactactivity", + new_name="stats_ct_actvt_org_date_idx", + old_fields=("org", "date"), + ), + migrations.AlterUniqueTogether( + name="contactactivity", + unique_together=set(), + ), + migrations.AddConstraint( + model_name="contactactivity", + constraint=models.UniqueConstraint( + fields=("org", "contact", "date"), name="stats_contactactivity_org_id_contact_date_348227aa_uniq" + ), + ), + ] diff --git a/ureport/stats/models.py b/ureport/stats/models.py index 6ef7625b1..80eaedadb 100644 --- a/ureport/stats/models.py +++ b/ureport/stats/models.py @@ -736,8 +736,15 @@ class ContactActivity(models.Model): used = models.BooleanField(null=True) class Meta: - index_together = (("org", "contact"), ("org", "date")) - unique_together = ("org", "contact", "date") + constraints = [ + models.UniqueConstraint( + fields=["org", "contact", "date"], name="stats_contactactivity_org_id_contact_date_348227aa_uniq" + ) + ] + indexes = [ + models.Index(fields=["org", "contact"], name="stats_ct_actvt_org_contact_idx"), + models.Index(fields=["org", "date"], name="stats_ct_actvt_org_date_idx"), + ] def generate_counters(self): generated_counters = dict()