diff --git a/latest_migrations.manifest b/latest_migrations.manifest index e052952856d52b..3079c62e846e37 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: 0450_externaldataschema_sync_frequency_interval_and_more +posthog: 0451_datawarehousetable_updated_at_and_more sessions: 0001_initial social_django: 0010_uid_db_index two_factor: 0007_auto_20201201_1019 diff --git a/posthog/migrations/0451_datawarehousetable_updated_at_and_more.py b/posthog/migrations/0451_datawarehousetable_updated_at_and_more.py new file mode 100644 index 00000000000000..b5ba9d16d99d59 --- /dev/null +++ b/posthog/migrations/0451_datawarehousetable_updated_at_and_more.py @@ -0,0 +1,32 @@ +# Generated by Django 4.2.14 on 2024-07-24 11:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("posthog", "0450_externaldataschema_sync_frequency_interval_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="datawarehousetable", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True, blank=True), + ), + migrations.AddField( + model_name="externaldatajob", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True, blank=True), + ), + migrations.AddField( + model_name="externaldataschema", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True, blank=True), + ), + migrations.AddField( + model_name="externaldatasource", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True, blank=True), + ), + ] diff --git a/posthog/models/utils.py b/posthog/models/utils.py index f16bd09984e13a..6bfcc81c308257 100644 --- a/posthog/models/utils.py +++ b/posthog/models/utils.py @@ -146,6 +146,13 @@ class Meta: abstract = True +class UpdatedMetaFields(models.Model): + updated_at: models.DateTimeField = models.DateTimeField(auto_now=True, null=True, blank=True) + + class Meta: + abstract = True + + class DeletedMetaFields(models.Model): deleted: models.BooleanField = models.BooleanField(null=True, blank=True) diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr index e1e2bd01a820a3..16bc71a7219e49 100644 --- a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr +++ b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr @@ -474,6 +474,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -518,6 +519,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -652,6 +654,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -696,6 +699,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -1408,6 +1412,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -1452,6 +1457,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -1816,6 +1822,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -1860,6 +1867,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -1931,6 +1939,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -1975,6 +1984,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -2394,6 +2404,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -2438,6 +2449,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -2509,6 +2521,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -2553,6 +2566,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -2935,6 +2949,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -2979,6 +2994,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -3106,6 +3122,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -3150,6 +3167,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -3533,6 +3551,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -3577,6 +3596,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -3648,6 +3668,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -3692,6 +3713,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -3864,6 +3886,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -3908,6 +3931,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -4010,6 +4034,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -4054,6 +4079,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -4415,6 +4441,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -4459,6 +4486,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -4530,6 +4558,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -4574,6 +4603,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -4912,6 +4942,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -4956,6 +4987,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -4992,6 +5024,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -5036,6 +5069,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -5107,6 +5141,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -5151,6 +5186,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -5508,6 +5544,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -5552,6 +5589,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -5641,6 +5679,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -5685,6 +5724,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -6039,6 +6079,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -6083,6 +6124,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -6154,6 +6196,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -6198,6 +6241,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -6257,6 +6301,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -6301,6 +6346,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", @@ -6610,6 +6656,7 @@ ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", "posthog_datawarehousetable"."deleted", "posthog_datawarehousetable"."id", "posthog_datawarehousetable"."name", @@ -6654,6 +6701,7 @@ "posthog_datawarehousecredential"."team_id", "posthog_externaldatasource"."created_by_id", "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", "posthog_externaldatasource"."id", "posthog_externaldatasource"."source_id", "posthog_externaldatasource"."connection_id", diff --git a/posthog/warehouse/models/external_data_job.py b/posthog/warehouse/models/external_data_job.py index 488f7ba0f92128..7b7f1cc15e1a81 100644 --- a/posthog/warehouse/models/external_data_job.py +++ b/posthog/warehouse/models/external_data_job.py @@ -2,14 +2,14 @@ from django.db.models import Prefetch from django.conf import settings from posthog.models.team import Team -from posthog.models.utils import CreatedMetaFields, UUIDModel, sane_repr +from posthog.models.utils import CreatedMetaFields, UUIDModel, UpdatedMetaFields, sane_repr from posthog.settings import TEST from posthog.warehouse.s3 import get_s3_client from uuid import UUID from posthog.warehouse.util import database_sync_to_async -class ExternalDataJob(CreatedMetaFields, UUIDModel): +class ExternalDataJob(CreatedMetaFields, UpdatedMetaFields, UUIDModel): class Status(models.TextChoices): RUNNING = "Running", "Running" FAILED = "Failed", "Failed" diff --git a/posthog/warehouse/models/external_data_schema.py b/posthog/warehouse/models/external_data_schema.py index 1303805e01c661..95bfb94a2f6249 100644 --- a/posthog/warehouse/models/external_data_schema.py +++ b/posthog/warehouse/models/external_data_schema.py @@ -5,7 +5,7 @@ from django_deprecate_fields import deprecate_field import snowflake.connector from posthog.models.team import Team -from posthog.models.utils import CreatedMetaFields, UUIDModel, sane_repr +from posthog.models.utils import CreatedMetaFields, UUIDModel, UpdatedMetaFields, sane_repr import uuid import psycopg2 import pymysql @@ -21,7 +21,7 @@ from posthog.warehouse.util import database_sync_to_async -class ExternalDataSchema(CreatedMetaFields, UUIDModel): +class ExternalDataSchema(CreatedMetaFields, UpdatedMetaFields, UUIDModel): class Status(models.TextChoices): RUNNING = "Running", "Running" PAUSED = "Paused", "Paused" diff --git a/posthog/warehouse/models/external_data_source.py b/posthog/warehouse/models/external_data_source.py index e6f617f79fbf96..0919362b80a2c0 100644 --- a/posthog/warehouse/models/external_data_source.py +++ b/posthog/warehouse/models/external_data_source.py @@ -2,7 +2,7 @@ from django.db import models from posthog.models.team import Team -from posthog.models.utils import CreatedMetaFields, UUIDModel, sane_repr +from posthog.models.utils import CreatedMetaFields, UUIDModel, UpdatedMetaFields, sane_repr from posthog.warehouse.util import database_sync_to_async from uuid import UUID @@ -12,7 +12,7 @@ logger = structlog.get_logger(__name__) -class ExternalDataSource(CreatedMetaFields, UUIDModel): +class ExternalDataSource(CreatedMetaFields, UpdatedMetaFields, UUIDModel): class Type(models.TextChoices): STRIPE = "Stripe", "Stripe" HUBSPOT = "Hubspot", "Hubspot" diff --git a/posthog/warehouse/models/table.py b/posthog/warehouse/models/table.py index a99ed5bcdf0b2a..b6454ea379d808 100644 --- a/posthog/warehouse/models/table.py +++ b/posthog/warehouse/models/table.py @@ -13,6 +13,7 @@ CreatedMetaFields, DeletedMetaFields, UUIDModel, + UpdatedMetaFields, sane_repr, ) from posthog.schema import DatabaseSerializedFieldType, HogQLQueryModifiers @@ -65,7 +66,7 @@ def get_queryset(self): ) -class DataWarehouseTable(CreatedMetaFields, UUIDModel, DeletedMetaFields): +class DataWarehouseTable(CreatedMetaFields, UpdatedMetaFields, UUIDModel, DeletedMetaFields): # loading external_data_source and credentials is easily N+1, # so we have a custom object manager meaning people can't forget to load them # this also means we _always_ have two joins whenever we load tables