From 7e12e548669999189886ce81bc182ebb85e95f2d Mon Sep 17 00:00:00 2001 From: Eric Duong Date: Wed, 9 Oct 2024 10:16:18 -0400 Subject: [PATCH] fix(data-warehouse): add edit to materialized views (#25400) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .../components/DatabaseTableTree/TreeRow.tsx | 8 +++++- .../external/DataWarehouseTables.tsx | 23 +++++++-------- latest_migrations.manifest | 2 +- ...85_alter_datawarehousesavedquery_status.py | 28 +++++++++++++++++++ posthog/warehouse/api/saved_query.py | 1 + .../models/datawarehouse_saved_query.py | 1 + 6 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 posthog/migrations/0485_alter_datawarehousesavedquery_status.py diff --git a/frontend/src/lib/components/DatabaseTableTree/TreeRow.tsx b/frontend/src/lib/components/DatabaseTableTree/TreeRow.tsx index 79661f2e5df3e..47a425e04243a 100644 --- a/frontend/src/lib/components/DatabaseTableTree/TreeRow.tsx +++ b/frontend/src/lib/components/DatabaseTableTree/TreeRow.tsx @@ -92,6 +92,9 @@ export function TreeFolderRow({ item, depth, onClick, selectedRow, dropdownOverl if (item.table.status === 'Failed') { return `Materialization failed` } + if (item.table.status === 'Modified') { + return `View definition modified since last materialization` + } if (item.table.status === 'Completed') { return `Last materialized ${humanFriendlyDetailedTime(item.table.last_run_at)}` } @@ -99,7 +102,7 @@ export function TreeFolderRow({ item, depth, onClick, selectedRow, dropdownOverl return '' } - const getIconColor = (): 'text-primary' | 'text-danger' | 'text-success' => { + const getIconColor = (): 'text-primary' | 'text-danger' | 'text-warning' | 'text-success' => { if (item.table?.type === 'materialized_view') { if (item.table.status === 'Running') { return 'text-primary' @@ -107,6 +110,9 @@ export function TreeFolderRow({ item, depth, onClick, selectedRow, dropdownOverl if (item.table.status === 'Failed') { return 'text-danger' } + if (item.table.status === 'Modified') { + return 'text-warning' + } } return 'text-success' } diff --git a/frontend/src/scenes/data-warehouse/external/DataWarehouseTables.tsx b/frontend/src/scenes/data-warehouse/external/DataWarehouseTables.tsx index 69b36f2557e10..501f59d0ddf44 100644 --- a/frontend/src/scenes/data-warehouse/external/DataWarehouseTables.tsx +++ b/frontend/src/scenes/data-warehouse/external/DataWarehouseTables.tsx @@ -131,17 +131,18 @@ export const DatabaseTableTreeWithItems = ({ inline }: DatabaseTableTreeProps): > Add join - {table.type == 'view' && ( - { - router.actions.push(urls.dataWarehouseView(table.id)) - }} - data-attr="schema-list-item-edit" - fullWidth - > - Edit view definition - - )} + {table.type == 'view' || + (table.type == 'materialized_view' && ( + { + router.actions.push(urls.dataWarehouseView(table.id)) + }} + data-attr="schema-list-item-edit" + fullWidth + > + Edit view definition + + ))} {featureFlags[FEATURE_FLAGS.DATA_MODELING] && table.type === 'view' && ( { diff --git a/latest_migrations.manifest b/latest_migrations.manifest index 7307753ccc3da..db08450e643c2 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: 0484_productintent +posthog: 0485_alter_datawarehousesavedquery_status sessions: 0001_initial social_django: 0010_uid_db_index two_factor: 0007_auto_20201201_1019 diff --git a/posthog/migrations/0485_alter_datawarehousesavedquery_status.py b/posthog/migrations/0485_alter_datawarehousesavedquery_status.py new file mode 100644 index 0000000000000..d29e283a3caa5 --- /dev/null +++ b/posthog/migrations/0485_alter_datawarehousesavedquery_status.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.15 on 2024-10-04 15:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("posthog", "0484_productintent"), + ] + + operations = [ + migrations.AlterField( + model_name="datawarehousesavedquery", + name="status", + field=models.CharField( + choices=[ + ("Cancelled", "Cancelled"), + ("Modified", "Modified"), + ("Completed", "Completed"), + ("Failed", "Failed"), + ("Running", "Running"), + ], + help_text="The status of when this SavedQuery last ran.", + max_length=64, + null=True, + ), + ), + ] diff --git a/posthog/warehouse/api/saved_query.py b/posthog/warehouse/api/saved_query.py index 018303911ba06..ac8c8e53022dd 100644 --- a/posthog/warehouse/api/saved_query.py +++ b/posthog/warehouse/api/saved_query.py @@ -94,6 +94,7 @@ def update(self, instance: Any, validated_data: Any) -> Any: try: view.columns = view.get_columns() view.external_tables = view.s3_tables + view.status = DataWarehouseSavedQuery.Status.MODIFIED except RecursionError: raise serializers.ValidationError("Model contains a cycle") diff --git a/posthog/warehouse/models/datawarehouse_saved_query.py b/posthog/warehouse/models/datawarehouse_saved_query.py index cfa833e0c6719..1d8aae6d70c46 100644 --- a/posthog/warehouse/models/datawarehouse_saved_query.py +++ b/posthog/warehouse/models/datawarehouse_saved_query.py @@ -46,6 +46,7 @@ class Status(models.TextChoices): """Possible states of this SavedQuery.""" CANCELLED = "Cancelled" + MODIFIED = "Modified" # if the model definition has changed and hasn't been materialized since COMPLETED = "Completed" FAILED = "Failed" RUNNING = "Running"