diff --git a/zerver/migrations/0001_initial.py b/zerver/migrations/0001_initial.py index 50f0fb4a17..45e99d5557 100644 --- a/zerver/migrations/0001_initial.py +++ b/zerver/migrations/0001_initial.py @@ -1,14 +1,15 @@ -# Generated by Django 1.11.2 on 2017-06-22 10:22 +# Generated by Django 5.0.7 on 2024-08-13 21:48 + import bitfield.models import django.contrib.auth.models +import django.contrib.postgres.indexes +import django.contrib.postgres.search import django.core.validators import django.db.models.deletion +import django.db.models.functions.text import django.utils.timezone from django.conf import settings -from django.contrib.postgres.indexes import GinIndex -from django.contrib.postgres.search import SearchVectorField from django.db import migrations, models -from django.db.models.functions import Upper from zerver.models.streams import generate_email_token_for_stream @@ -52,21 +53,8 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async BEFORE INSERT OR UPDATE OF subject, rendered_content ON zerver_message FOR EACH ROW EXECUTE PROCEDURE append_to_fts_update_log(); """ + operations = [ - migrations.CreateModel( - name="PreregistrationUser", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("email", models.EmailField(max_length=75)), - ("invited_at", models.DateTimeField(auto_now=True)), - ("status", models.IntegerField(default=0)), - ], - ), migrations.CreateModel( name="Recipient", fields=[ @@ -79,6 +67,9 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ("type_id", models.IntegerField(db_index=True)), ("type", models.PositiveSmallIntegerField(db_index=True)), ], + options={ + "unique_together": {("type", "type_id")}, + }, ), migrations.CreateModel( name="Huddle", @@ -111,9 +102,16 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ("name_changes_disabled", models.BooleanField(default=False)), ("date_created", models.DateTimeField(default=django.utils.timezone.now)), ("deactivated", models.BooleanField(default=False)), + ("create_stream_by_admins_only", models.BooleanField(default=False)), + ("allow_message_editing", models.BooleanField(default=True)), + ("message_content_edit_limit_seconds", models.IntegerField(default=600)), + ("default_language", models.CharField(default="en", max_length=50)), ], options={ - "permissions": (("administer", "Administer a realm"),), + "permissions": ( + ("administer", "Administer a realm"), + ("api_super_user", "Can send messages as other users for mirroring"), + ), }, ), migrations.CreateModel( @@ -129,45 +127,7 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ( "realm", models.ForeignKey( - null=True, on_delete=django.db.models.deletion.CASCADE, to="zerver.Realm" - ), - ), - ], - ), - migrations.CreateModel( - name="RealmEmoji", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("name", models.TextField()), - ("img_url", models.TextField()), - ( - "realm", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to="zerver.Realm" - ), - ), - ], - ), - migrations.CreateModel( - name="RealmFilter", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("pattern", models.TextField()), - ("url_format_string", models.TextField()), - ( - "realm", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to="zerver.Realm" + null=True, on_delete=django.db.models.deletion.CASCADE, to="zerver.realm" ), ), ], @@ -212,9 +172,7 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ("password", models.CharField(max_length=128, verbose_name="password")), ( "last_login", - models.DateTimeField( - default=django.utils.timezone.now, verbose_name="last login" - ), + models.DateTimeField(blank=True, null=True, verbose_name="last login"), ), ( "is_superuser", @@ -224,10 +182,10 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async verbose_name="superuser status", ), ), - ("email", models.EmailField(db_index=True, max_length=75, unique=True)), + ("email", models.EmailField(db_index=True, max_length=254, unique=True)), ("is_staff", models.BooleanField(default=False)), - ("is_active", models.BooleanField(default=True)), - ("is_bot", models.BooleanField(default=False)), + ("is_active", models.BooleanField(db_index=True, default=True)), + ("is_bot", models.BooleanField(db_index=True, default=False)), ("date_joined", models.DateTimeField(default=django.utils.timezone.now)), ("is_mirror_dummy", models.BooleanField(default=False)), ("full_name", models.CharField(max_length=100)), @@ -235,8 +193,8 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ("pointer", models.IntegerField()), ("last_pointer_updater", models.CharField(max_length=64)), ("api_key", models.CharField(max_length=32)), - ("enable_stream_desktop_notifications", models.BooleanField(default=True)), - ("enable_stream_sounds", models.BooleanField(default=True)), + ("enable_stream_desktop_notifications", models.BooleanField(default=False)), + ("enable_stream_sounds", models.BooleanField(default=False)), ("enable_desktop_notifications", models.BooleanField(default=True)), ("enable_sounds", models.BooleanField(default=True)), ("enable_offline_email_notifications", models.BooleanField(default=True)), @@ -249,7 +207,7 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ), ("rate_limits", models.CharField(default="", max_length=100)), ("default_all_public_streams", models.BooleanField(default=False)), - ("enter_sends", models.BooleanField(null=True, default=True)), + ("enter_sends", models.BooleanField(default=True, null=True)), ("autoscroll_forever", models.BooleanField(default=False)), ("twenty_four_hour_time", models.BooleanField(default=False)), ( @@ -285,22 +243,45 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async to=settings.AUTH_USER_MODEL, ), ), + ( + "groups", + models.ManyToManyField( + blank=True, + help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.", + related_name="user_set", + related_query_name="user", + to="auth.group", + verbose_name="groups", + ), + ), + ( + "realm", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zerver.realm" + ), + ), + ( + "user_permissions", + models.ManyToManyField( + blank=True, + help_text="Specific permissions for this user.", + related_name="user_set", + related_query_name="user", + to="auth.permission", + verbose_name="user permissions", + ), + ), + ("left_side_userlist", models.BooleanField(default=False)), + ("is_api_super_user", models.BooleanField(db_index=True, default=False)), + ("is_realm_admin", models.BooleanField(db_index=True, default=False)), + ("bot_type", models.PositiveSmallIntegerField(db_index=True, null=True)), + ("default_language", models.CharField(default="en", max_length=50)), + ("tos_version", models.CharField(max_length=10, null=True)), ], options={ "abstract": False, }, ), - migrations.CreateModel( - name="DefaultStream", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ], - ), migrations.CreateModel( name="Message", fields=[ @@ -320,130 +301,25 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ("has_attachment", models.BooleanField(db_index=True, default=False)), ("has_image", models.BooleanField(db_index=True, default=False)), ("has_link", models.BooleanField(db_index=True, default=False)), - ], - ), - migrations.CreateModel( - name="PushDeviceToken", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("kind", models.PositiveSmallIntegerField(choices=[(1, "apns"), (2, "gcm")])), - ("token", models.CharField(max_length=4096, unique=True)), - ( - "last_updated", - models.DateTimeField(auto_now=True, default=django.utils.timezone.now), - ), - ("ios_app_id", models.TextField(null=True)), - ( - "user", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL - ), - ), - ], - ), - migrations.CreateModel( - name="Referral", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("email", models.EmailField(max_length=75)), - ("timestamp", models.DateTimeField(auto_now_add=True)), - ( - "user_profile", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL - ), - ), - ], - ), - migrations.CreateModel( - name="Stream", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("name", models.CharField(db_index=True, max_length=60)), - ("invite_only", models.BooleanField(null=True, default=False)), - ( - "email_token", - models.CharField(default=generate_email_token_for_stream, max_length=32), - ), - ("description", models.CharField(default="", max_length=1024)), - ("date_created", models.DateTimeField(default=django.utils.timezone.now)), - ("deactivated", models.BooleanField(default=False)), - ( - "realm", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to="zerver.Realm" - ), - ), - ], - ), - migrations.CreateModel( - name="Subscription", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("active", models.BooleanField(default=True)), - ("in_home_view", models.BooleanField(null=True, default=True)), - ("color", models.CharField(default="#c2c2c2", max_length=10)), - ("desktop_notifications", models.BooleanField(default=True)), - ("audible_notifications", models.BooleanField(default=True)), - ("notifications", models.BooleanField(default=False)), ( "recipient", models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to="zerver.Recipient" + on_delete=django.db.models.deletion.CASCADE, to="zerver.recipient" ), ), ( - "user_profile", + "sender", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL ), ), - ], - ), - migrations.CreateModel( - name="UserActivity", - fields=[ ( - "id", - models.AutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("query", models.CharField(db_index=True, max_length=50)), - ("count", models.IntegerField()), - ("last_visit", models.DateTimeField(verbose_name="last visit")), - ( - "client", + "sending_client", models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to="zerver.Client" - ), - ), - ( - "user_profile", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + on_delete=django.db.models.deletion.CASCADE, to="zerver.client" ), ), + ("search_tsvector", django.contrib.postgres.search.SearchVectorField(null=True)), ], ), migrations.CreateModel( @@ -465,6 +341,34 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ), ], ), + migrations.CreateModel( + name="UserPresence", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("timestamp", models.DateTimeField(verbose_name="presence changed")), + ("status", models.PositiveSmallIntegerField(default=1)), + ( + "client", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zerver.client" + ), + ), + ( + "user_profile", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + ), + ], + options={ + "unique_together": {("user_profile", "client")}, + }, + ), migrations.CreateModel( name="UserMessage", fields=[ @@ -497,7 +401,7 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ( "message", models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to="zerver.Message" + on_delete=django.db.models.deletion.CASCADE, to="zerver.message" ), ), ( @@ -507,9 +411,158 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async ), ), ], + options={ + "unique_together": {("user_profile", "message")}, + }, + ), + migrations.CreateModel( + name="UserActivity", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("query", models.CharField(db_index=True, max_length=50)), + ("count", models.IntegerField()), + ("last_visit", models.DateTimeField(verbose_name="last visit")), + ( + "client", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zerver.client" + ), + ), + ( + "user_profile", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + ), + ], + options={ + "unique_together": {("user_profile", "client", "query")}, + }, + ), + migrations.CreateModel( + name="Stream", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("name", models.CharField(db_index=True, max_length=60)), + ("invite_only", models.BooleanField(default=False, null=True)), + ( + "email_token", + models.CharField(default=generate_email_token_for_stream, max_length=32), + ), + ("description", models.CharField(default="", max_length=1024)), + ("date_created", models.DateTimeField(default=django.utils.timezone.now)), + ("deactivated", models.BooleanField(default=False)), + ( + "realm", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zerver.realm" + ), + ), + ], + options={ + "unique_together": {("name", "realm")}, + }, + ), + migrations.CreateModel( + name="RealmFilter", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("pattern", models.TextField()), + ("url_format_string", models.TextField()), + ( + "realm", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zerver.realm" + ), + ), + ], + options={ + "unique_together": {("realm", "pattern")}, + }, + ), + migrations.CreateModel( + name="DefaultStream", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ( + "realm", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zerver.realm" + ), + ), + ( + "stream", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zerver.stream" + ), + ), + ], + options={ + "unique_together": {("realm", "stream")}, + }, + ), + migrations.CreateModel( + name="PushDeviceToken", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("kind", models.PositiveSmallIntegerField(choices=[(1, "apns"), (2, "gcm")])), + ("token", models.CharField(max_length=4096, unique=True)), + ("last_updated", models.DateTimeField(auto_now=True)), + ("ios_app_id", models.TextField(null=True)), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + ), + ], + ), + migrations.CreateModel( + name="Referral", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("email", models.EmailField(max_length=254)), + ("timestamp", models.DateTimeField(auto_now_add=True)), + ( + "user_profile", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL + ), + ), + ], ), migrations.CreateModel( - name="UserPresence", + name="RealmEmoji", fields=[ ( "id", @@ -517,227 +570,58 @@ CREATE TRIGGER zerver_message_update_search_tsvector_async auto_created=True, primary_key=True, serialize=False, verbose_name="ID" ), ), - ("timestamp", models.DateTimeField(verbose_name="presence changed")), - ("status", models.PositiveSmallIntegerField(default=1)), ( - "client", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, to="zerver.Client" + "name", + models.TextField( + validators=[ + django.core.validators.MinLengthValidator(1), + django.core.validators.RegexValidator( + message="Invalid characters in emoji name", + regex="^[0-9a-zA-Z.\\-_]+(?