models: Convert deprecated index_together option to indexes.

index_together is slated for removal in Django 5.1:
https://docs.djangoproject.com/en/4.2/internals/deprecation/#deprecation-removed-in-5-1

We set the optional index names to match the previously generated
index names to avoid adding new migrations.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-06-11 12:22:36 -07:00 committed by Tim Abbott
parent c238327899
commit 7e707270f0
9 changed files with 117 additions and 44 deletions

View File

@ -1,5 +1,5 @@
# Generated by Django 1.10.5 on 2017-02-01 22:28
from django.db import migrations
from django.db import migrations, models
class Migration(migrations.Migration):
@ -9,16 +9,25 @@ class Migration(migrations.Migration):
]
operations = [
migrations.AlterIndexTogether(
name="realmcount",
index_together={("property", "end_time")},
migrations.AddIndex(
model_name="realmcount",
index=models.Index(
fields=["property", "end_time"],
name="analytics_realmcount_property_end_time_3b60396b_idx",
),
migrations.AlterIndexTogether(
name="streamcount",
index_together={("property", "realm", "end_time")},
),
migrations.AlterIndexTogether(
name="usercount",
index_together={("property", "realm", "end_time")},
migrations.AddIndex(
model_name="streamcount",
index=models.Index(
fields=["property", "realm", "end_time"],
name="analytics_streamcount_property_realm_id_end_time_155ae930_idx",
),
),
migrations.AddIndex(
model_name="usercount",
index=models.Index(
fields=["property", "realm", "end_time"],
name="analytics_usercount_property_realm_id_end_time_591dbec1_idx",
),
),
]

View File

@ -79,7 +79,12 @@ class RealmCount(BaseCount):
name="unique_realm_count_null_subgroup",
),
]
index_together = ["property", "end_time"]
indexes = [
models.Index(
fields=["property", "end_time"],
name="analytics_realmcount_property_end_time_3b60396b_idx",
)
]
def __str__(self) -> str:
return f"{self.realm!r} {self.property} {self.subgroup} {self.value}"
@ -105,7 +110,12 @@ class UserCount(BaseCount):
]
# This index dramatically improves the performance of
# aggregating from users to realms
index_together = ["property", "realm", "end_time"]
indexes = [
models.Index(
fields=["property", "realm", "end_time"],
name="analytics_usercount_property_realm_id_end_time_591dbec1_idx",
)
]
def __str__(self) -> str:
return f"{self.user!r} {self.property} {self.subgroup} {self.value}"
@ -131,7 +141,12 @@ class StreamCount(BaseCount):
]
# This index dramatically improves the performance of
# aggregating from streams to realms
index_together = ["property", "realm", "end_time"]
indexes = [
models.Index(
fields=["property", "realm", "end_time"],
name="analytics_streamcount_property_realm_id_end_time_155ae930_idx",
)
]
def __str__(self) -> str:
return f"{self.stream!r} {self.property} {self.subgroup} {self.value} {self.id}"

View File

@ -14,8 +14,11 @@ class Migration(migrations.Migration):
name="realm",
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="zerver.Realm"),
),
migrations.AlterIndexTogether(
name="userpresence",
index_together={("realm", "timestamp")},
migrations.AddIndex(
model_name="userpresence",
index=models.Index(
fields=["realm", "timestamp"],
name="zerver_userpresence_realm_id_timestamp_25f410da_idx",
),
),
]

View File

@ -1,6 +1,6 @@
# Generated by Django 3.2.6 on 2021-08-31 19:17
from django.db import migrations
from django.db import migrations, models
class Migration(migrations.Migration):
@ -9,8 +9,11 @@ class Migration(migrations.Migration):
]
operations = [
migrations.AlterIndexTogether(
name="useractivityinterval",
index_together={("user_profile", "end")},
migrations.AddIndex(
model_name="useractivityinterval",
index=models.Index(
fields=["user_profile", "end"],
name="zerver_useractivityinterval_user_profile_id_end_bb3bfc37_idx",
),
),
]

View File

@ -127,7 +127,12 @@ class Migration(migrations.Migration):
migrations.RenameModel(
old_name="UserPresence",
new_name="UserPresenceOld",
)
),
migrations.RenameIndex(
model_name="userpresenceold",
old_name="zerver_userpresence_realm_id_timestamp_25f410da_idx",
new_name="zerver_userpresenceold_realm_id_timestamp_52ef5fd3_idx",
),
],
),
migrations.CreateModel(
@ -164,8 +169,19 @@ class Migration(migrations.Migration):
),
),
],
options={
"index_together": {("realm", "last_active_time"), ("realm", "last_connected_time")},
},
),
migrations.AddIndex(
model_name="userpresence",
index=models.Index(
fields=["realm", "last_active_time"],
name="zerver_userpresence_realm_id_last_active_time_1c5aa9a2_idx",
),
),
migrations.AddIndex(
model_name="userpresence",
index=models.Index(
fields=["realm", "last_connected_time"],
name="zerver_userpresence_realm_id_last_connected_time_98d2fc9f_idx",
),
),
]

View File

@ -4133,8 +4133,11 @@ class UserActivityInterval(models.Model):
end = models.DateTimeField("end time", db_index=True)
class Meta:
index_together = [
("user_profile", "end"),
indexes = [
models.Index(
fields=["user_profile", "end"],
name="zerver_useractivityinterval_user_profile_id_end_bb3bfc37_idx",
),
]
@ -4174,9 +4177,15 @@ class UserPresence(models.Model):
LEGACY_STATUS_IDLE_INT = 2
class Meta:
index_together = [
("realm", "last_active_time"),
("realm", "last_connected_time"),
indexes = [
models.Index(
fields=["realm", "last_active_time"],
name="zerver_userpresence_realm_id_last_active_time_1c5aa9a2_idx",
),
models.Index(
fields=["realm", "last_connected_time"],
name="zerver_userpresence_realm_id_last_connected_time_98d2fc9f_idx",
),
]
@staticmethod

View File

@ -59,9 +59,12 @@ class Migration(migrations.Migration):
name="remoterealmcount",
unique_together={("server", "realm_id", "property", "subgroup", "end_time")},
),
migrations.AlterIndexTogether(
name="remoterealmcount",
index_together={("property", "end_time")},
migrations.AddIndex(
model_name="remoterealmcount",
index=models.Index(
fields=["property", "end_time"],
name="zilencer_remoterealmcount_property_end_time_506a0b38_idx",
),
),
migrations.AlterUniqueTogether(
name="remoteinstallationcount",

View File

@ -1,6 +1,6 @@
# Generated by Django 1.11.20 on 2019-04-23 20:17
from django.db import migrations
from django.db import migrations, models
class Migration(migrations.Migration):
@ -9,12 +9,18 @@ class Migration(migrations.Migration):
]
operations = [
migrations.AlterIndexTogether(
name="remoteinstallationcount",
index_together={("server", "remote_id")},
migrations.AddIndex(
model_name="remoteinstallationcount",
index=models.Index(
fields=["server", "remote_id"],
name="zilencer_remoteinstallat_server_id_remote_id_f72e4c30_idx",
),
),
migrations.AddIndex(
model_name="remoterealmcount",
index=models.Index(
fields=["server", "remote_id"],
name="zilencer_remoterealmcount_server_id_remote_id_de1573d8_idx",
),
migrations.AlterIndexTogether(
name="remoterealmcount",
index_together={("property", "end_time"), ("server", "remote_id")},
),
]

View File

@ -115,8 +115,11 @@ class RemoteInstallationCount(BaseCount):
class Meta:
unique_together = ("server", "property", "subgroup", "end_time")
index_together = [
["server", "remote_id"],
indexes = [
models.Index(
fields=["server", "remote_id"],
name="zilencer_remoteinstallat_server_id_remote_id_f72e4c30_idx",
),
]
def __str__(self) -> str:
@ -132,9 +135,15 @@ class RemoteRealmCount(BaseCount):
class Meta:
unique_together = ("server", "realm_id", "property", "subgroup", "end_time")
index_together = [
["property", "end_time"],
["server", "remote_id"],
indexes = [
models.Index(
fields=["property", "end_time"],
name="zilencer_remoterealmcount_property_end_time_506a0b38_idx",
),
models.Index(
fields=["server", "remote_id"],
name="zilencer_remoterealmcount_server_id_remote_id_de1573d8_idx",
),
]
def __str__(self) -> str: