From 8c5ba23522087e0dc5026f217866c82ebcd29a4e Mon Sep 17 00:00:00 2001 From: Robbie Date: Sun, 21 Apr 2024 22:12:34 +0100 Subject: [PATCH 1/3] Add migration in advance of session properties PR --- latest_migrations.manifest | 2 +- ...inition_property_type_is_valid_and_more.py | 46 +++++++++++++++++++ posthog/models/property_definition.py | 2 + 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py diff --git a/latest_migrations.manifest b/latest_migrations.manifest index dac9ed4ce4539..ede9b35bf2662 100644 --- a/latest_migrations.manifest +++ b/latest_migrations.manifest @@ -5,7 +5,7 @@ contenttypes: 0002_remove_content_type_name ee: 0016_rolemembership_organization_member otp_static: 0002_throttling otp_totp: 0002_auto_20190420_0723 -posthog: 0403_plugin_has_private_access +posthog: 0404_remove_propertydefinition_property_type_is_valid_and_more sessions: 0001_initial social_django: 0010_uid_db_index two_factor: 0007_auto_20201201_1019 diff --git a/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py b/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py new file mode 100644 index 0000000000000..ae84002a79b58 --- /dev/null +++ b/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py @@ -0,0 +1,46 @@ +# Generated by Django 4.2.11 on 2024-04-21 21:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("posthog", "0403_plugin_has_private_access"), + ] + + operations = [ + migrations.RemoveConstraint( + model_name="propertydefinition", + name="property_type_is_valid", + ), + migrations.AlterField( + model_name="propertydefinition", + name="property_type", + field=models.CharField( + blank=True, + choices=[ + ("DateTime", "DateTime"), + ("String", "String"), + ("Numeric", "Numeric"), + ("Boolean", "Boolean"), + ("Duration", "Duration"), + ], + max_length=50, + null=True, + ), + ), + migrations.AlterField( + model_name="propertydefinition", + name="type", + field=models.PositiveSmallIntegerField( + choices=[(1, "event"), (2, "person"), (3, "group"), (4, "session")], default=1 + ), + ), + migrations.AddConstraint( + model_name="propertydefinition", + constraint=models.CheckConstraint( + check=models.Q(("property_type__in", ["DateTime", "String", "Numeric", "Boolean", "Duration"])), + name="property_type_is_valid", + ), + ), + ] diff --git a/posthog/models/property_definition.py b/posthog/models/property_definition.py index 0a6f89354a639..8c8b9d6c773b4 100644 --- a/posthog/models/property_definition.py +++ b/posthog/models/property_definition.py @@ -12,6 +12,7 @@ class PropertyType(models.TextChoices): String = "String", "String" Numeric = "Numeric", "Numeric" Boolean = "Boolean", "Boolean" + Duration = "Duration", "Duration" class PropertyFormat(models.TextChoices): @@ -34,6 +35,7 @@ class Type(models.IntegerChoices): EVENT = 1, "event" PERSON = 2, "person" GROUP = 3, "group" + SESSION = 4, "session" team: models.ForeignKey = models.ForeignKey( Team, From 549b311b5c54e1836c6d0bd018130ec80d237f2a Mon Sep 17 00:00:00 2001 From: Robbie Coomber Date: Tue, 23 Apr 2024 21:09:42 +0100 Subject: [PATCH 2/3] Use AddConstraintNotValid --- mypy-baseline.txt | 1 + ...move_propertydefinition_property_type_is_valid_and_more.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mypy-baseline.txt b/mypy-baseline.txt index 3c6bbf22089c0..9b607b6222cd3 100644 --- a/mypy-baseline.txt +++ b/mypy-baseline.txt @@ -366,6 +366,7 @@ posthog/session_recordings/queries/session_recording_list_from_replay_summary.py posthog/session_recordings/queries/session_recording_list_from_replay_summary.py:0: note: If the method is meant to be abstract, use @abc.abstractmethod posthog/session_recordings/queries/session_recording_list_from_replay_summary.py:0: error: Missing return statement [empty-body] posthog/session_recordings/queries/session_recording_list_from_replay_summary.py:0: note: If the method is meant to be abstract, use @abc.abstractmethod +posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py:0: error: Module "django.contrib.postgres.operations" has no attribute "AddConstraintNotValid" [attr-defined] posthog/hogql_queries/test/test_query_runner.py:0: error: Variable "TestQueryRunner" is not valid as a type [valid-type] posthog/hogql_queries/test/test_query_runner.py:0: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases posthog/hogql_queries/test/test_query_runner.py:0: error: Invalid base class "TestQueryRunner" [misc] diff --git a/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py b/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py index ae84002a79b58..a90c8214064bd 100644 --- a/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py +++ b/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py @@ -1,5 +1,5 @@ # Generated by Django 4.2.11 on 2024-04-21 21:11 - +from django.contrib.postgres.operations import AddConstraintNotValid from django.db import migrations, models @@ -36,7 +36,7 @@ class Migration(migrations.Migration): choices=[(1, "event"), (2, "person"), (3, "group"), (4, "session")], default=1 ), ), - migrations.AddConstraint( + AddConstraintNotValid( model_name="propertydefinition", constraint=models.CheckConstraint( check=models.Q(("property_type__in", ["DateTime", "String", "Numeric", "Boolean", "Duration"])), From 2a4651091b8b7b6d030a5e1f6399f5ba1f85fe40 Mon Sep 17 00:00:00 2001 From: Robbie Date: Wed, 24 Apr 2024 08:53:00 +0100 Subject: [PATCH 3/3] Add comment --- ..._remove_propertydefinition_property_type_is_valid_and_more.py | 1 + 1 file changed, 1 insertion(+) diff --git a/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py b/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py index a90c8214064bd..ac34ed62af7b9 100644 --- a/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py +++ b/posthog/migrations/0404_remove_propertydefinition_property_type_is_valid_and_more.py @@ -36,6 +36,7 @@ class Migration(migrations.Migration): choices=[(1, "event"), (2, "person"), (3, "group"), (4, "session")], default=1 ), ), + # changed from migrations.AddConstraint. See migration 0405 for where we validate the constraint AddConstraintNotValid( model_name="propertydefinition", constraint=models.CheckConstraint(