From a56e5079fd16cc54d57376227b35ed8f3c6b25e8 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 13 Aug 2024 13:05:40 -0700 Subject: [PATCH] migrations: Squash zilencer migrations. Created using manage.py squashmigrations with a couple changes: - Patched Django to optimize AddConstraints/RemoveConstraints properly. - Used the StateOperations from the migrations.SeparateDatabaseAndState section in migration 0060, so that the constraint changes could be optimized properly. - Removed dependencies on zerver, since this project does not actually have any dependencies on zerver migrations. --- ..._0064_remotezulipserver_last_merge_base.py | 595 ++++++++++++++++++ 1 file changed, 595 insertions(+) create mode 100644 zilencer/migrations/0001_squashed_0064_remotezulipserver_last_merge_base.py diff --git a/zilencer/migrations/0001_squashed_0064_remotezulipserver_last_merge_base.py b/zilencer/migrations/0001_squashed_0064_remotezulipserver_last_merge_base.py new file mode 100644 index 0000000000..528875aaf6 --- /dev/null +++ b/zilencer/migrations/0001_squashed_0064_remotezulipserver_last_merge_base.py @@ -0,0 +1,595 @@ +# Generated by Django 5.0.7 on 2024-08-13 20:11 + +import django.core.serializers.json +import django.db.models.deletion +import django.utils.timezone +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + replaces = [ + ("zilencer", "0001_initial"), + ("zilencer", "0002_remote_zulip_server"), + ("zilencer", "0003_add_default_for_remotezulipserver_last_updated_field"), + ("zilencer", "0004_remove_deployment_model"), + ("zilencer", "0005_remotepushdevicetoken_fix_uniqueness"), + ("zilencer", "0006_customer"), + ("zilencer", "0007_remotezulipserver_fix_uniqueness"), + ("zilencer", "0008_customer_billing_user"), + ("zilencer", "0009_plan"), + ("zilencer", "0010_billingprocessor"), + ("zilencer", "0011_customer_has_billing_relationship"), + ("zilencer", "0012_coupon"), + ("zilencer", "0013_remove_customer_billing_user"), + ("zilencer", "0014_cleanup_pushdevicetoken"), + ("zilencer", "0015_delete_billing"), + ("zilencer", "0016_remote_counts"), + ("zilencer", "0017_installationcount_indexes"), + ("zilencer", "0018_remoterealmauditlog"), + ("zilencer", "0019_remotezulipserver_plan_type"), + ("zilencer", "0020_remotezulipserverauditlog"), + ("zilencer", "0021_alter_remotezulipserver_uuid"), + ("zilencer", "0022_remotezulipserver_create_audit_log_backfill"), + ("zilencer", "0023_remotezulipserver_deactivated"), + ("zilencer", "0024_remotepushdevicetoken_user_uuid"), + ("zilencer", "0025_alter_remotepushdevicetoken_user_id_drop_index"), + ("zilencer", "0026_auditlog_models_extra_data_json"), + ("zilencer", "0027_backfill_remote_realmauditlog_extradata_to_json_field"), + ("zilencer", "0028_rename_extradatajson_remoteauditlog_extra_data"), + ("zilencer", "0029_update_remoterealm_indexes"), + ("zilencer", "0030_alter_remoteinstallationcount_remote_id"), + ("zilencer", "0031_alter_remoteinstallationcount_remote_id_and_more"), + ("zilencer", "0032_remotepushdevicetoken_backfill_ios_app_id"), + ("zilencer", "0033_remoterealm"), + ("zilencer", "0034_remoterealmauditlog_remote_realm_and_more"), + ("zilencer", "0035_remoterealmcount_remote_realm_and_more"), + ("zilencer", "0036_remotezulipserver_last_version"), + ("zilencer", "0037_alter_remoteinstallationcount_unique_together_and_more"), + ("zilencer", "0038_unique_server_remote_id"), + ("zilencer", "0039_remoterealm_org_type"), + ("zilencer", "0040_remoterealm_authentication_methods_remoterealm_name"), + ("zilencer", "0041_remotezulipserver_org_type"), + ("zilencer", "0042_alter_remoterealmauditlog_realm_id"), + ("zilencer", "0043_remotepushdevicetoken_remote_realm"), + ("zilencer", "0044_remoterealmbillinguser"), + ("zilencer", "0045_remoterealmauditlog_zilencer_remoterealmauditlog_server_realm_and_more"), + ("zilencer", "0046_remotezulipserver_last_audit_log_update"), + ("zilencer", "0047_preregistrationremoteserverbillinguser_and_more"), + ("zilencer", "0048_remotezulipserver_last_api_feature_level"), + ("zilencer", "0049_alter_remoterealmbillinguser_unique_together_and_more"), + ("zilencer", "0050_preregistrationremoterealmbillinguser_created_user_and_more"), + ("zilencer", "0051_remoterealm_is_system_bot_realm"), + ("zilencer", "0052_alter_remoterealm_plan_type_and_more"), + ("zilencer", "0053_remoterealmauditlog_acting_remote_user_and_more"), + ("zilencer", "0054_remoterealmbillinguser_enable_maintenance_release_emails_and_more"), + ("zilencer", "0055_remoteserverbillinguser_tos_version"), + ("zilencer", "0056_remoterealm_realm_locally_deleted"), + ("zilencer", "0057_remoterealm_last_request_timestamp_and_more"), + ("zilencer", "0058_remoteinstallationcount_add_mobile_pushes_forwarded_index"), + ("zilencer", "0059_remoterealmauditlog_add_synced_billing_event_type_index"), + ( + "zilencer", + "0060_remove_remoterealmcount_unique_remote_realm_installation_count_and_more", + ), + ("zilencer", "0061_clean_count_tables"), + ("zilencer", "0062_alter_remoteinstallationcount_id_and_more"), + ("zilencer", "0063_convert_ids_to_bigints"), + ("zilencer", "0064_remotezulipserver_last_merge_base"), + ] + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="RemoteZulipServer", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("uuid", models.UUIDField(unique=True)), + ("api_key", models.CharField(max_length=64)), + ("hostname", models.CharField(max_length=128)), + ("contact_email", models.EmailField(blank=True, max_length=254)), + ("last_updated", models.DateTimeField(auto_now=True, verbose_name="last updated")), + ("plan_type", models.PositiveSmallIntegerField(default=100)), + ("deactivated", models.BooleanField(default=False)), + ("last_version", models.CharField(max_length=128, null=True)), + ( + "org_type", + models.PositiveSmallIntegerField( + choices=[ + (0, "Unspecified"), + (10, "Business"), + (20, "Open-source project"), + (30, "Education (non-profit)"), + (35, "Education (for-profit)"), + (40, "Research"), + (50, "Event or conference"), + (60, "Non-profit (registered)"), + (70, "Government"), + (80, "Political group"), + (90, "Community"), + (100, "Personal"), + (1000, "Other"), + ], + default=0, + ), + ), + ("last_audit_log_update", models.DateTimeField(null=True)), + ("last_api_feature_level", models.PositiveIntegerField(null=True)), + ("last_request_datetime", models.DateTimeField(null=True)), + ("last_merge_base", models.CharField(max_length=128, null=True)), + ], + ), + migrations.CreateModel( + name="RemoteRealm", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("uuid", models.UUIDField(unique=True)), + ("uuid_owner_secret", models.TextField()), + ("host", models.TextField()), + ("last_updated", models.DateTimeField(auto_now=True, verbose_name="last updated")), + ("registration_deactivated", models.BooleanField(default=False)), + ("realm_deactivated", models.BooleanField(default=False)), + ("realm_date_created", models.DateTimeField()), + ("plan_type", models.PositiveSmallIntegerField(db_index=True, default=100)), + ( + "server", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remotezulipserver" + ), + ), + ( + "org_type", + models.PositiveSmallIntegerField( + choices=[ + (0, "Unspecified"), + (10, "Business"), + (20, "Open-source project"), + (30, "Education (non-profit)"), + (35, "Education (for-profit)"), + (40, "Research"), + (50, "Event or conference"), + (60, "Non-profit (registered)"), + (70, "Government"), + (80, "Political group"), + (90, "Community"), + (100, "Personal"), + (1000, "Other"), + ], + default=0, + ), + ), + ("authentication_methods", models.JSONField(default=dict)), + ("name", models.TextField(default="")), + ("is_system_bot_realm", models.BooleanField(default=False)), + ("realm_locally_deleted", models.BooleanField(default=False)), + ("last_request_datetime", models.DateTimeField(null=True)), + ], + ), + migrations.CreateModel( + name="RemoteServerBillingUser", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("email", models.EmailField(max_length=254)), + ("full_name", models.TextField(default="")), + ( + "remote_server", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remotezulipserver" + ), + ), + ("date_joined", models.DateTimeField(default=django.utils.timezone.now)), + ("is_active", models.BooleanField(default=True)), + ("last_login", models.DateTimeField(null=True)), + ("enable_maintenance_release_emails", models.BooleanField(default=True)), + ("enable_major_release_emails", models.BooleanField(default=True)), + ("tos_version", models.TextField(default="-1")), + ], + options={ + "unique_together": {("remote_server", "email")}, + }, + ), + migrations.CreateModel( + name="RemoteRealmBillingUser", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("user_uuid", models.UUIDField()), + ("full_name", models.TextField(default="")), + ("email", models.EmailField(max_length=254)), + ("tos_version", models.TextField(default="-1")), + ( + "remote_realm", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remoterealm" + ), + ), + ("date_joined", models.DateTimeField(default=django.utils.timezone.now)), + ("is_active", models.BooleanField(default=True)), + ("last_login", models.DateTimeField(null=True)), + ("enable_maintenance_release_emails", models.BooleanField(default=True)), + ("enable_major_release_emails", models.BooleanField(default=True)), + ], + options={ + "unique_together": {("remote_realm", "user_uuid")}, + }, + ), + migrations.CreateModel( + name="RemoteInstallationCount", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("property", models.CharField(max_length=32)), + ("subgroup", models.CharField(max_length=16, null=True)), + ("end_time", models.DateTimeField()), + ("value", models.BigIntegerField()), + ("remote_id", models.IntegerField(null=True)), + ( + "server", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remotezulipserver" + ), + ), + ], + options={ + "unique_together": set(), + "indexes": [ + models.Index( + condition=models.Q(("property", "mobile_pushes_forwarded::day")), + fields=["server_id", "end_time"], + name="zilencer_remoteinstallationcount_server_end_time_mobile_pushes_forwarded", + ) + ], + "constraints": [ + models.UniqueConstraint( + condition=models.Q(("subgroup__isnull", False)), + fields=("server", "property", "subgroup", "end_time"), + name="unique_remote_installation_count", + ), + models.UniqueConstraint( + condition=models.Q(("subgroup__isnull", True)), + fields=("server", "property", "end_time"), + name="unique_remote_installation_count_null_subgroup", + ), + models.UniqueConstraint( + condition=models.Q(("remote_id__isnull", False)), + fields=("server", "remote_id"), + name="unique_remote_installation_count_server_id_remote_id", + ), + ], + }, + ), + migrations.CreateModel( + name="RemoteRealmCount", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("property", models.CharField(max_length=32)), + ("subgroup", models.CharField(max_length=16, null=True)), + ("end_time", models.DateTimeField()), + ("value", models.BigIntegerField()), + ("realm_id", models.IntegerField(null=True)), + ("remote_id", models.IntegerField(null=True)), + ( + "server", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remotezulipserver" + ), + ), + ( + "remote_realm", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="zilencer.remoterealm", + ), + ), + ], + options={ + "unique_together": set(), + "indexes": [ + models.Index( + fields=["property", "end_time"], + name="zilencer_remoterealmcount_property_end_time_506a0b38_idx", + ), + models.Index( + condition=models.Q(("remote_realm__isnull", True)), + fields=["server", "realm_id"], + name="zilencer_remoterealmcount_server_realm", + ), + models.Index( + condition=models.Q(("remote_realm__isnull", True)), + fields=["server"], + name="zilencer_remoterealmcount_server", + ), + ], + "constraints": [ + models.UniqueConstraint( + condition=models.Q(("remote_id__isnull", False)), + fields=("server", "remote_id"), + name="unique_remote_realm_installation_count_server_id_remote_id", + ), + models.UniqueConstraint( + condition=models.Q(("subgroup__isnull", False)), + fields=("server", "realm_id", "property", "subgroup", "end_time"), + name="unique_server_realm_installation_count", + ), + models.UniqueConstraint( + condition=models.Q(("subgroup__isnull", True)), + fields=("server", "realm_id", "property", "end_time"), + name="unique_server_realm_installation_count_null_subgroup", + ), + models.UniqueConstraint( + condition=models.Q(("subgroup__isnull", False)), + fields=("remote_realm_id", "property", "subgroup", "end_time"), + name="unique_remote_realm_installation_count", + ), + models.UniqueConstraint( + condition=models.Q(("subgroup__isnull", True)), + fields=("remote_realm_id", "property", "end_time"), + name="unique_remote_realm_installation_count_null_subgroup", + ), + ], + }, + ), + migrations.CreateModel( + name="PreregistrationRemoteRealmBillingUser", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("user_uuid", models.UUIDField()), + ("email", models.EmailField(max_length=254)), + ("status", models.IntegerField(default=0)), + ("next_page", models.TextField(null=True)), + ("uri_scheme", models.TextField()), + ( + "remote_realm", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remoterealm" + ), + ), + ( + "created_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="zilencer.remoterealmbillinguser", + ), + ), + ("date_joined", models.DateTimeField(default=django.utils.timezone.now)), + ], + options={ + "abstract": False, + }, + ), + migrations.CreateModel( + name="PreregistrationRemoteServerBillingUser", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("email", models.EmailField(max_length=254)), + ("status", models.IntegerField(default=0)), + ("next_page", models.TextField(null=True)), + ( + "remote_server", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remotezulipserver" + ), + ), + ( + "created_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="zilencer.remoteserverbillinguser", + ), + ), + ("date_joined", models.DateTimeField(default=django.utils.timezone.now)), + ], + options={ + "abstract": False, + }, + ), + migrations.CreateModel( + name="RemotePushDeviceToken", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("user_id", models.BigIntegerField(null=True)), + ("kind", models.PositiveSmallIntegerField(choices=[(1, "apns"), (2, "gcm")])), + ("token", models.CharField(db_index=True, max_length=4096)), + ("last_updated", models.DateTimeField(auto_now=True)), + ("ios_app_id", models.TextField(null=True)), + ( + "server", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remotezulipserver" + ), + ), + ("user_uuid", models.UUIDField(null=True)), + ( + "remote_realm", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="zilencer.remoterealm", + ), + ), + ], + options={ + "unique_together": { + ("server", "user_id", "kind", "token"), + ("server", "user_uuid", "kind", "token"), + }, + }, + ), + migrations.CreateModel( + name="RemoteRealmAuditLog", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("realm_id", models.IntegerField(blank=True, null=True)), + ("remote_id", models.IntegerField(null=True)), + ("event_time", models.DateTimeField(db_index=True)), + ("backfilled", models.BooleanField(default=False)), + ("event_type", models.PositiveSmallIntegerField()), + ( + "server", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remotezulipserver" + ), + ), + ( + "extra_data", + models.JSONField( + default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder + ), + ), + ( + "remote_realm", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="zilencer.remoterealm", + ), + ), + ( + "acting_remote_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="zilencer.remoterealmbillinguser", + ), + ), + ( + "acting_support_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "constraints": [ + models.UniqueConstraint( + fields=("server", "remote_id"), + name="zilencer_remoterealmauditlog_server_remote", + ) + ], + "indexes": [ + models.Index( + fields=["server", "realm_id", "remote_id"], + name="zilencer_remoterealmauditlog_server_realm_remote", + ), + models.Index( + condition=models.Q(("remote_realm__isnull", True)), + fields=["server", "realm_id"], + name="zilencer_remoterealmauditlog_server_realm", + ), + models.Index( + condition=models.Q(("remote_realm__isnull", True)), + fields=["server"], + name="zilencer_remoterealmauditlog_server", + ), + models.Index( + condition=models.Q( + ("event_type__in", [101, 102, 103, 104, 105, 201, 202, 229]) + ), + fields=["remote_realm_id", "id"], + name="zilencer_remoterealmauditlog_synced_billing_events", + ), + ], + }, + ), + migrations.CreateModel( + name="RemoteZulipServerAuditLog", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("event_time", models.DateTimeField(db_index=True)), + ("backfilled", models.BooleanField(default=False)), + ("event_type", models.PositiveSmallIntegerField()), + ( + "server", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="zilencer.remotezulipserver" + ), + ), + ( + "extra_data", + models.JSONField( + default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder + ), + ), + ( + "acting_remote_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="zilencer.remoteserverbillinguser", + ), + ), + ( + "acting_support_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "abstract": False, + }, + ), + ]