From 37803406e5a71992bf368f1e54d9e194fc407bd1 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Wed, 29 May 2024 20:05:32 +0000 Subject: [PATCH] models: Migrate ids of UserActivity and UserActivityInterval to bigint. These models have no external references, and are among the larger tables. Migrate them to bigints, starting with `useractivityinterval` which is less likely to be being touched. --- ...tivity_id_alter_useractivityinterval_id.py | 26 +++++++++++++++++++ zerver/models/user_activity.py | 6 +++++ 2 files changed, 32 insertions(+) create mode 100644 zerver/migrations/0530_alter_useractivity_id_alter_useractivityinterval_id.py diff --git a/zerver/migrations/0530_alter_useractivity_id_alter_useractivityinterval_id.py b/zerver/migrations/0530_alter_useractivity_id_alter_useractivityinterval_id.py new file mode 100644 index 0000000000..0d4099f09b --- /dev/null +++ b/zerver/migrations/0530_alter_useractivity_id_alter_useractivityinterval_id.py @@ -0,0 +1,26 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + atomic = False + + dependencies = [ + ("zerver", "0529_fts_bigint_id"), + ] + + operations = [ + migrations.AlterField( + model_name="useractivityinterval", + name="id", + field=models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + migrations.AlterField( + model_name="useractivity", + name="id", + field=models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ] diff --git a/zerver/models/user_activity.py b/zerver/models/user_activity.py index 7f979ba1fe..c550e8abaa 100644 --- a/zerver/models/user_activity.py +++ b/zerver/models/user_activity.py @@ -19,6 +19,9 @@ class UserActivity(models.Model): and database migration purposes. """ + id = models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ) user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE) client = models.ForeignKey(Client, on_delete=CASCADE) query = models.CharField(max_length=50, db_index=True) @@ -33,6 +36,9 @@ class UserActivity(models.Model): class UserActivityInterval(models.Model): MIN_INTERVAL_LENGTH = timedelta(minutes=15) + id = models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ) user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE) start = models.DateTimeField("start time", db_index=True) end = models.DateTimeField("end time", db_index=True)