Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Use default db table name for UserTopic.
Abhijeet Prasad Bodas4455dac42465
diff --git a/zerver/lib/export.py b/zerver/lib/export.pyindex 1bcbcb00930..8a861ed53f5 100644--- a/zerver/lib/export.py+++ b/zerver/lib/export.py@@ -163,7 +163,7 @@ ALL_ZULIP_TABLES = {"zerver_userprofile_groups","zerver_userprofile_user_permissions","zerver_userstatus",- "zerver_mutedtopic",+ "zerver_usertopic","zerver_muteduser",}@@ -277,7 +277,7 @@ ANALYTICS_TABLES = {DATE_FIELDS: Dict[TableName, List[Field]] = {"zerver_attachment": ["create_time"],"zerver_message": ["last_edit_time", "date_sent"],- "zerver_mutedtopic": ["last_updated"],+ "zerver_usertopic": ["last_updated"],"zerver_realm": ["date_created"],"zerver_stream": ["date_created"],"zerver_useractivity": ["last_visit"],@@ -756,7 +756,7 @@ def get_realm_config() -> Config:)Config(- table="zerver_mutedtopic",+ table="zerver_usertopic",model=UserTopic,normal_parent=user_profile_config,parent_key="user_profile__in",diff --git a/zerver/lib/fix_unreads.py b/zerver/lib/fix_unreads.pyindex a29c462bb88..83576fe48bc 100644--- a/zerver/lib/fix_unreads.py+++ b/zerver/lib/fix_unreads.py@@ -33,7 +33,7 @@ def build_topic_mute_checker(recipient_id,topic_nameFROM- zerver_mutedtopic+ zerver_usertopicWHEREuser_profile_id = %s"""diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.pyindex 4f4a4b6e952..2e6e6edeeff 100644--- a/zerver/lib/import_realm.py+++ b/zerver/lib/import_realm.py@@ -116,7 +116,7 @@ ID_MAP: Dict[str, Dict[int, int]] = {"realmauditlog": {},"recipient_to_huddle_map": {},"userhotspot": {},- "mutedtopic": {},+ "usertopic": {},"muteduser": {},"service": {},"usergroup": {},@@ -382,6 +382,10 @@ def idseq(model_class: Any) -> str:return "zerver_botuserstatedata_id_seq"elif model_class == BotConfigData:return "zerver_botuserconfigdata_id_seq"+ elif model_class == UserTopic:+ # The database table for this model was renamed from `mutedtopic` to+ # `usertopic`, but the name of the sequence object remained the same.+ return "zerver_mutedtopic_id_seq"return f"{model_class._meta.db_table}_id_seq"@@ -1091,12 +1095,12 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Reaupdate_model_ids(UserHotspot, data, "userhotspot")bulk_import_model(data, UserHotspot)- if "zerver_mutedtopic" in data:- fix_datetime_fields(data, "zerver_mutedtopic")- re_map_foreign_keys(data, "zerver_mutedtopic", "user_profile", related_table="user_profile")- re_map_foreign_keys(data, "zerver_mutedtopic", "stream", related_table="stream")- re_map_foreign_keys(data, "zerver_mutedtopic", "recipient", related_table="recipient")- update_model_ids(UserTopic, data, "mutedtopic")+ if "zerver_usertopic" in data:+ fix_datetime_fields(data, "zerver_usertopic")+ re_map_foreign_keys(data, "zerver_usertopic", "user_profile", related_table="user_profile")+ re_map_foreign_keys(data, "zerver_usertopic", "stream", related_table="stream")+ re_map_foreign_keys(data, "zerver_usertopic", "recipient", related_table="recipient")+ update_model_ids(UserTopic, data, "usertopic")bulk_import_model(data, UserTopic)if "zerver_muteduser" in data:diff --git a/zerver/migrations/0349_alter_usertopic_table.py b/zerver/migrations/0349_alter_usertopic_table.pynew file mode 100644index 00000000000..c10bc1c3457--- /dev/null+++ b/zerver/migrations/0349_alter_usertopic_table.py@@ -0,0 +1,17 @@+# Generated by Django 3.2.5 on 2021-07-31 05:38++from django.db import migrations+++class Migration(migrations.Migration):++ dependencies = [+ ("zerver", "0348_rename_date_muted_usertopic_last_updated"),+ ]++ operations = [+ migrations.AlterModelTable(+ name="UserTopic",+ table=None,+ ),+ ]diff --git a/zerver/models.py b/zerver/models.pyindex fbb8d2210d6..0a46946e037 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -2208,11 +2208,6 @@ class UserTopic(models.Model):class Meta:unique_together = ("user_profile", "stream", "topic_name")- # This model was originally called "MutedTopic". We- # generalized it to "UserTopic", but have not yet done the- # database migration to rename the table and indexes.- db_table = "zerver_mutedtopic"-def __str__(self) -> str:return f"<UserTopic: ({self.user_profile.email}, {self.stream.name}, {self.topic_name}, {self.last_updated})>"