Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add migration in advance of session properties PR #21703

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion latest_migrations.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions mypy-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are types borked here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it does run locally though

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]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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


class Migration(migrations.Migration):
dependencies = [
("posthog", "0403_plugin_has_private_access"),
]

operations = [
migrations.RemoveConstraint(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the drawback we have is even a canary deploy doesn't help us since it's the DB that we lock if something does go wrong

but I also don't think we have a good alternative here, this is what Django is going to do to make this change 🙈

probably we need to merge this when the system isn't under load and with someone from infra on hand ready to help fix all the things if it does cause downtime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and feel happily foolish if it goes in without incident :))

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
),
),
Comment on lines +16 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC these are not really database changes so they have no effect on the DB

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(i.e. Django lists them as migrations but they are no-op for postgres)

# changed from migrations.AddConstraint. See migration 0405 for where we validate the constraint
AddConstraintNotValid(
model_name="propertydefinition",
constraint=models.CheckConstraint(
check=models.Q(("property_type__in", ["DateTime", "String", "Numeric", "Boolean", "Duration"])),
name="property_type_is_valid",
),
),
]
2 changes: 2 additions & 0 deletions posthog/models/property_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PropertyType(models.TextChoices):
String = "String", "String"
Numeric = "Numeric", "Numeric"
Boolean = "Boolean", "Boolean"
Duration = "Duration", "Duration"


class PropertyFormat(models.TextChoices):
Expand All @@ -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,
Expand Down
Loading