:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(warehouse-suggestions): suggest deprecating or deleting unused views (#125704)
Thiago Salvatore96fbe386cf56
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 8b12e6e0d8af..47245f8a50f1 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -17462,14 +17462,18 @@ snapshots:hash: v1.k794b7964.b3793a018b9fc7d1019402ec5216189d26ae85000cbb9d91ede5b7ac7f6528c3.V-ICrhJc-LkfYh8MsK8Q2AoJxCcRhqLIDNvGQ0uyFugwarehouse-suggestions-suggested-certifications--banner--light:hash: v1.k794b7964.4398ae40c8e28494481e73b72c49315fd5294380aaa8f4f579c53b120e95d2f3.qj1-k55d9dyizhho1p59SKxeUPeAKHr6ZRnFAkcZgIA+ warehouse-suggestions-suggested-certifications--delete-dialog--dark:+ hash: v1.k794b7964.aad2607c019ac52b9556e91abd03d3a233ab8fdd198567fd1e129b934675d251.tSQKOmix1NM8XrB1tQ1mf_ddO7ZcMvpSpt1-mlY4REA+ warehouse-suggestions-suggested-certifications--delete-dialog--light:+ hash: v1.k794b7964.a9541f596401a8a9a9fbad1941304b64f5fb2ae8ab2a458e189b3e2cbd0c40ef.jRI2zgnjkgGptnLv2kYbB2DCHQor9oeuXjosAsweeIcwarehouse-suggestions-suggested-certifications--deprecate-dialog--dark:- hash: v1.k794b7964.09b0aec605e49d00a60ef65ad6a4e44157179bfcd307e22500d1f0c95dcca84b.ffeyTu9F9ltSOuDHuRiBk66vNteeBGXBOuZdMSNUEWQ+ hash: v1.k794b7964.569fbd69081ec9226b2537abd808af36a5af9479f9a916934db6b86400fc3575.iXbK1xwKnUOBSuwq1ysK1z081fchT6WbgT6mAE0H5aswarehouse-suggestions-suggested-certifications--deprecate-dialog--light:- hash: v1.k794b7964.275d7a88a60faa93a269cf2845b2699cbfdf64e3e44915475a0b2bee1cd74d5f.NhxpoIwZXgvWwn3rUmWDa0TNkY2A7ZVGRJmHW1vAuBM+ hash: v1.k794b7964.52c60a9e5d167d90d4c5606f0032ae4aaa99dad729d6cd3282d8dc3ee9d20889.tUy7qtGeFR3r-LLD3dqj8qxl20pbg4rl0qo9xpERdPkwarehouse-suggestions-suggested-certifications--review-dialog--dark:- hash: v1.k794b7964.6dcbacf41e20c4bea01deeb9dfe4d35f2448360bf979c9b28a79fa2e70c9b093.vkNS26vk41QQyUFkJwTUZ6pxCQkisgogPmtUMRCOLQU+ hash: v1.k794b7964.79329703679886eb0cc766b817ed635ab872e231b2d0c157aee6bd29caca951f.FGhDdgEznM4SRrNmEYuX88lQwOMw2_ZhdWZMNKQGWMswarehouse-suggestions-suggested-certifications--review-dialog--light:- hash: v1.k794b7964.10018e84324c52d7139e7329ad735059c12c23b62abd4da8c7b8db9ad04fb0f6.83Sg6I66DFRMw1gR9ZiuxhtiS1iRLdiTl-6B99FYlOw+ hash: v1.k794b7964.b6bb52e92fb9f9b665b0c37374beaf8b5df6873cc787803bc36f9e0c368153e6.Cxvr8LuJdvGINBPf-TwPCo0DlkEk09S7PNxK6N09hiowarehouse-suggestions-suggested-certifications--review-dialog-narrow--dark:hash: v1.k794b7964.09bce81ef734200f2bf6cb83ab6f721fe5bf3fa49baf8e7d3efc8ba2aef669b5.odxYkoZ6E1lVK5TmS2efjmW-Yc63cmsNvj01Tj1dVAYwarehouse-suggestions-suggested-certifications--review-dialog-narrow--light:diff --git a/products/data_modeling/backend/facade/api.py b/products/data_modeling/backend/facade/api.pyindex 3f429ae6ba05..77a13b13e611 100644--- a/products/data_modeling/backend/facade/api.py+++ b/products/data_modeling/backend/facade/api.py@@ -21,6 +21,7 @@ _LAZY = {"MissingDagNodeError": "logic.saved_query_dag_sync","blocked_lineage_node_id": "logic.saved_query_dag_sync","check_saved_query_deletable": "logic.saved_query_dag_sync",+ "delete_saved_query_by_id": "logic.saved_query_deletion","delete_node_from_dag": "logic.saved_query_dag_sync","delete_node": "logic.saved_query_dag_sync","delete_orphaned_table_nodes": "logic.saved_query_dag_sync",diff --git a/products/data_modeling/backend/logic/saved_query_deletion.py b/products/data_modeling/backend/logic/saved_query_deletion.pynew file mode 100644index 000000000000..2137dba8da18--- /dev/null+++ b/products/data_modeling/backend/logic/saved_query_deletion.py@@ -0,0 +1,67 @@+from uuid import UUID++from django.db.models import Q++import structlog+from rest_framework import serializers++from posthog.exceptions_capture import capture_exception+from posthog.models import User+from posthog.models.activity_logging.activity_log import Detail, Trigger, log_activity++from products.data_modeling.backend.logic.node_materialization import SavedQueryNotFoundError+from products.data_modeling.backend.logic.saved_query_dag_sync import HasDependentsError, check_saved_query_deletable+from products.data_modeling.backend.models.datawarehouse_saved_query import DataWarehouseSavedQuery+from products.data_tools.backend.facade.models import DataWarehouseJoin++logger = structlog.get_logger(__name__)++SAVED_QUERY_ACTIVITY_SCOPE = "DataWarehouseSavedQuery"+DELETED_ACTIVITY = "deleted"+++def delete_saved_query(saved_query: DataWarehouseSavedQuery) -> None:+ if saved_query.managed_viewset is not None:+ raise serializers.ValidationError(+ "Cannot delete a query from a managed viewset directly. Disable the managed viewset instead."+ )++ try:+ check_saved_query_deletable(saved_query.team_id, saved_query.id)+ except HasDependentsError:+ raise+ except Exception as e:+ capture_exception(e)+ logger.exception("Failed to check dependents of saved query", saved_query_name=saved_query.name)++ for join in DataWarehouseJoin.objects.filter(+ Q(team_id=saved_query.team_id)+ & (Q(source_table_name=saved_query.name) | Q(joining_table_name=saved_query.name))+ ).exclude(deleted=True):+ join.soft_delete()++ saved_query.revert_materialization()+ saved_query.soft_delete()+++def delete_saved_query_by_id(+ team_id: int, saved_query_id: UUID, *, user: User, was_impersonated: bool, trigger: Trigger | None = None+) -> None:+ """Delete a live saved query and log it as deleted by `user`."""+ saved_query = (+ DataWarehouseSavedQuery.objects.filter(team_id=team_id, id=saved_query_id).exclude(deleted=True).first()+ )+ if saved_query is None:+ raise SavedQueryNotFoundError(f"Saved query {saved_query_id} not found for team {team_id}")+ name = saved_query.name+ delete_saved_query(saved_query)+ log_activity(+ organization_id=saved_query.team.organization_id,+ team_id=team_id,+ user=user,+ was_impersonated=was_impersonated,+ item_id=saved_query.id,+ scope=SAVED_QUERY_ACTIVITY_SCOPE,+ activity=DELETED_ACTIVITY,+ detail=Detail(name=name, trigger=trigger),+ )diff --git a/products/data_warehouse/backend/presentation/views/saved_query/folders.py b/products/data_warehouse/backend/presentation/views/saved_query/folders.pyindex 8a1df6a26efe..bd500d0709ba 100644--- a/products/data_warehouse/backend/presentation/views/saved_query/folders.py+++ b/products/data_warehouse/backend/presentation/views/saved_query/folders.py@@ -1,7 +1,7 @@"""Saved-query folders: the serializer and the viewset that organize views in the SQL editor."""import uuid-from typing import Any+from typing import Any, castfrom django.db import transactionfrom django.db.models import Count, IntegerField, OuterRef, Subquery@@ -11,17 +11,18 @@ from rest_framework import request, response, serializers, status, viewsetsfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.shared import UserBasicSerializer+from posthog.helpers.impersonation import is_impersonated+from posthog.models import Userfrom posthog.permissions import is_service_authfrom products.access_control.backend.presentation.access_control import (AccessControlViewSetMixin,UserAccessControlSerializerMixin,)+from products.data_modeling.backend.facade.api import delete_saved_query_by_idfrom products.data_modeling.backend.facade.models import DataWarehouseSavedQueryfrom products.data_tools.backend.facade.models import DataWarehouseSavedQueryFolder-from . import lifecycle-class DataWarehouseSavedQueryFolderSerializer(UserAccessControlSerializerMixin, serializers.ModelSerializer):created_by = UserBasicSerializer(read_only=True)@@ -118,12 +119,15 @@ class DataWarehouseSavedQueryFolderViewSet(TeamAndOrgViewSetMixin, AccessControlf"Cannot delete this folder because these views still have dependencies outside the folder: {', '.join(blocked_names)}")- self._delete_in_dependency_order(saved_queries)+ self._delete_in_dependency_order(+ saved_queries, user=cast(User, request.user), was_impersonated=is_impersonated(request)+ )folder.delete()return response.Response(status=status.HTTP_204_NO_CONTENT)- @staticmethod- def _delete_in_dependency_order(saved_queries: list[DataWarehouseSavedQuery]) -> None:+ def _delete_in_dependency_order(+ self, saved_queries: list[DataWarehouseSavedQuery], *, user: User, was_impersonated: bool+ ) -> None:"""Delete dependents before their sources; the caller has already ruled out outside dependents."""from products.data_modeling.backend.facade.api import HasDependentsError@@ -132,7 +136,7 @@ class DataWarehouseSavedQueryFolderViewSet(TeamAndOrgViewSetMixin, AccessControldeleted_ids: list[uuid.UUID] = []for saved_query_id, saved_query in remaining.items():try:- lifecycle.delete_saved_query(saved_query)+ delete_saved_query_by_id(self.team_id, saved_query.id, user=user, was_impersonated=was_impersonated)deleted_ids.append(saved_query_id)except HasDependentsError:continuediff --git a/products/data_warehouse/backend/presentation/views/saved_query/lifecycle.py b/products/data_warehouse/backend/presentation/views/saved_query/lifecycle.pyindex df4fabd04fda..f1cf06caef34 100644--- a/products/data_warehouse/backend/presentation/views/saved_query/lifecycle.py+++ b/products/data_warehouse/backend/presentation/views/saved_query/lifecycle.py@@ -3,49 +3,12 @@from collections.abc import Sequencefrom typing import TYPE_CHECKING-from django.db.models import Q--import structlog-from rest_framework import serializers--from posthog.exceptions_capture import capture_exception-from products.access_control.backend.facade.user_access_control import UserAccessControlfrom products.data_modeling.backend.facade.contracts import Dependent-from products.data_modeling.backend.facade.models import DataWarehouseSavedQuery-from products.data_tools.backend.facade.models import DataWarehouseJoinif TYPE_CHECKING:from products.data_modeling.backend.facade.api import HasDependentsError-logger = structlog.get_logger(__name__)---def delete_saved_query(saved_query: DataWarehouseSavedQuery) -> None:- from products.data_modeling.backend.facade.api import HasDependentsError, check_saved_query_deletable-- if saved_query.managed_viewset is not None:- raise serializers.ValidationError(- "Cannot delete a query from a managed viewset directly. Disable the managed viewset instead."- )-- try:- check_saved_query_deletable(saved_query.team_id, saved_query.id)- except HasDependentsError:- raise- except Exception as e:- capture_exception(e)- logger.exception("Failed to check dependents of saved query", saved_query_name=saved_query.name)-- for join in DataWarehouseJoin.objects.filter(- Q(team_id=saved_query.team_id)- & (Q(source_table_name=saved_query.name) | Q(joining_table_name=saved_query.name))- ).exclude(deleted=True):- join.soft_delete()-- saved_query.revert_materialization()- saved_query.soft_delete()-def _readable_saved_query_ids(dependents: Sequence[Dependent], user_access_control: UserAccessControldiff --git a/products/data_warehouse/backend/presentation/views/saved_query/viewset.py b/products/data_warehouse/backend/presentation/views/saved_query/viewset.pyindex c30dbcb0acc3..3c68f4c34de8 100644--- a/products/data_warehouse/backend/presentation/views/saved_query/viewset.py+++ b/products/data_warehouse/backend/presentation/views/saved_query/viewset.py@@ -34,6 +34,7 @@ from products.data_modeling.backend.facade.api import (MaterializationRefusedError,MaterializationRunDirection,SavedQueryNotFoundError,+ delete_saved_query_by_id,disable_saved_query_materialization,enable_saved_query_materialization,run_related_node_materializations,@@ -286,7 +287,9 @@ class DataWarehouseSavedQueryViewSet(TeamAndOrgViewSetMixin, AccessControlViewSeinstance: DataWarehouseSavedQuery = self.get_object()name = instance.nametry:- lifecycle.delete_saved_query(instance)+ delete_saved_query_by_id(+ self.team_id, instance.id, user=cast(User, request.user), was_impersonated=is_impersonated(request)+ )except HasDependentsError as dependents_error:visible = lifecycle.visible_dependents(dependents_error.dependents, self.user_access_control)raise DependentsValidationError(@@ -294,17 +297,6 @@ class DataWarehouseSavedQueryViewSet(TeamAndOrgViewSetMixin, AccessControlViewSenode_id=lifecycle.refusal_node_id(dependents_error, visible, self.user_access_control),)- log_activity(- organization_id=self.team.organization_id,- team_id=self.team_id,- user=cast(User, request.user),- was_impersonated=is_impersonated(request),- item_id=instance.id,- scope="DataWarehouseSavedQuery",- activity="deleted",- detail=Detail(name=name),- )-return response.Response(status=status.HTTP_204_NO_CONTENT)@extend_schema(diff --git a/products/warehouse_suggestions/backend/facade/contracts.py b/products/warehouse_suggestions/backend/facade/contracts.pyindex eeefb95da502..deb74073612d 100644--- a/products/warehouse_suggestions/backend/facade/contracts.py+++ b/products/warehouse_suggestions/backend/facade/contracts.py@@ -46,6 +46,7 @@ class DeprecatePayload:subject_name: strrefresh_seconds_per_month: floatrefresh_bytes_per_month: float+ materialized: bool = True@frozen@@ -189,6 +190,7 @@ class AcceptOptions:unique_key: tuple[str, ...] | None = Nonelookback_seconds: int | None = Nonekeep_materialized: bool | None = None+ delete_view: bool | None = None@frozen@@ -196,7 +198,13 @@ class UnmaterializationAsset:saved_query_id: str-CreatedAsset = CertificationAsset | MaterializationAsset | UnmaterializationAsset+@frozen+class DeletionAsset:+ saved_query_id: str+ stopped_materialization: bool+++CreatedAsset = CertificationAsset | MaterializationAsset | UnmaterializationAsset | DeletionAsset@frozendiff --git a/products/warehouse_suggestions/backend/logic/accept.py b/products/warehouse_suggestions/backend/logic/accept.pyindex 304c81fe7232..52cd1df1bbd8 100644--- a/products/warehouse_suggestions/backend/logic/accept.py+++ b/products/warehouse_suggestions/backend/logic/accept.py@@ -11,6 +11,7 @@ from posthog.models.activity_logging.activity_log import Triggerfrom products.data_catalog.backend.facade.api import certifications_for_team, certify, deprecate, propose_certificationfrom products.data_catalog.backend.facade.enums import CertificationStatusfrom products.data_modeling.backend.facade.api import (+ HasDependentsError,IncrementalConfig,IncrementalConfigRefusedError,MaterializationFailedError,@@ -18,6 +19,7 @@ from products.data_modeling.backend.facade.api import (MaterializationRefusedError,SavedQueryNotFoundError,definition_database,+ delete_saved_query_by_id,dependent_saved_query_ids,disable_saved_query_materialization,enable_saved_query_materialization,@@ -41,6 +43,7 @@ from ..facade.contracts import (AcceptOptions,CertificationAsset,CreatedAsset,+ DeletionAsset,DeprecatePayload,MaterializationAsset,MaterializePayload,@@ -64,6 +67,7 @@ from .analytics import SuggestionOutcome, report_outcomesfrom .candidates.base import inlining_could_deny_a_reader, reads_direct_sourcefrom .candidates.unmaterialize import effective_definitionfrom .payloads import payload_from_json+from .rules import RULESfrom .suggestions import HUMAN_TRANSITIONS, Transitions, transition_toif TYPE_CHECKING:@@ -93,6 +97,14 @@ class Acceptor(ABC):KEEP_MATERIALIZED_FIELD = "keep_materialized"+DELETE_VIEW_FIELD = "delete_view"+DELETE_NEEDS_EVERY_DAY_OF_READS = (+ "Some days in the read window have no read data, so a view read only on those days would look unread. "+ "Mark it deprecated instead."+)+ALREADY_MARKED_DEPRECATED = (+ "This suggestion was already accepted by marking the view deprecated. Delete the view from its page instead."+)WAREHOUSE_SUGGESTION_TRIGGER_JOB_TYPE = "warehouse_suggestion"OTHER_VIEWS_READ_IT = "Other views now read from this view."SYNCS_READ_IT = "This view now feeds person properties, account properties, a destination or a workflow."@@ -145,6 +157,47 @@ class CertificationAcceptor(Acceptor):return existing+class DeprecateAcceptor(CertificationAcceptor):+ @property+ def option_fields(self) -> frozenset[str]:+ return super().option_fields | {DELETE_VIEW_FIELD}++ def accept(+ self, suggestion: WarehouseSuggestion, payload: SuggestionPayload, request: AcceptRequest+ ) -> CreatedAsset:+ if not request.options.delete_view:+ return super().accept(suggestion, payload, request)+ if suggestion.evidence.get("days_with_data", 0) < RULES.deprecate.min_days_with_data_to_delete:+ raise AcceptOptionRefusedError(DELETE_VIEW_FIELD, DELETE_NEEDS_EVERY_DAY_OF_READS)+ blocker = _delete_blocker(suggestion.team_id, suggestion.subject_id)+ if blocker is not None:+ raise SuggestionOutdatedError(blocker)+ stopped_materialization = saved_query_still_materializes(suggestion.team_id, suggestion.subject_id)+ try:+ delete_saved_query_by_id(+ suggestion.team_id,+ suggestion.subject_id,+ user=request.user,+ was_impersonated=request.was_impersonated,+ trigger=suggestion_trigger(suggestion),+ )+ except SavedQueryNotFoundError:+ raise SuggestionSubjectGoneError(WarehouseSuggestionSubjectKind.SAVED_QUERY)+ except HasDependentsError:+ raise SuggestionOutdatedError(OTHER_VIEWS_READ_IT)+ return DeletionAsset(saved_query_id=str(suggestion.subject_id), stopped_materialization=stopped_materialization)+++def _delete_blocker(team_id: int, saved_query_id: UUID) -> str | None:+ if dependent_saved_query_ids(team_id, [saved_query_id]).get(saved_query_id):+ return OTHER_VIEWS_READ_IT+ if saved_query_id in saved_queries_feeding_consumers(team_id, [saved_query_id]):+ return SYNCS_READ_IT+ if reads_direct_source(team_id, saved_query_id, direct_access_table_ids(team_id)):+ return READS_DIRECT_SOURCE+ return None++def _may_stop_materializing(suggestion: WarehouseSuggestion, options: AcceptOptions) -> bool:if suggestion.subject_kind != WarehouseSuggestionSubjectKind.SAVED_QUERY or options.keep_materialized:return False@@ -257,7 +310,7 @@ UNIQUE_KEY_FIELD = "unique_key"class MaterializeAcceptor(Acceptor):@propertydef option_fields(self) -> frozenset[str]:- return frozenset(field.name for field in fields(AcceptOptions)) - {KEEP_MATERIALIZED_FIELD}+ return frozenset(field.name for field in fields(AcceptOptions)) - {KEEP_MATERIALIZED_FIELD, DELETE_VIEW_FIELD}def accept(self, suggestion: WarehouseSuggestion, payload: SuggestionPayload, request: AcceptRequest@@ -366,7 +419,7 @@ ACCEPTORS: Mapping[WarehouseSuggestionKind, Acceptor] = {WarehouseSuggestionKind.CERTIFY: CertificationAcceptor(status=CertificationStatus.CERTIFIED, apply=certify, reuses_existing=False),- WarehouseSuggestionKind.DEPRECATE: CertificationAcceptor(+ WarehouseSuggestionKind.DEPRECATE: DeprecateAcceptor(status=CertificationStatus.DEPRECATED, apply=deprecate, reuses_existing=True, stops_materialization=True),WarehouseSuggestionKind.MATERIALIZE: MaterializeAcceptor(),@@ -421,6 +474,8 @@ def _accept(team_id: int, suggestion_id: UUID, request: AcceptRequest) -> Accept_refuse_options_the_kind_ignores(acceptor, kind, request.options)status = WarehouseSuggestionStatus(suggestion.status)if status == WarehouseSuggestionStatus.ACCEPTED:+ if request.options.delete_view and _kept_the_view(suggestion):+ raise SuggestionOutdatedError(ALREADY_MARKED_DEPRECATED)return AcceptOutcome(suggestion=suggestion, newly_accepted=False)if status != WarehouseSuggestionStatus.PROPOSED:raise SuggestionAlreadyDecidedError(status, WarehouseSuggestionStatus.ACCEPTED)@@ -470,7 +525,7 @@ def refresh_savings(created_asset: CreatedAsset, payload: SuggestionPayload) ->def _stopped_materialization(created_asset: CreatedAsset) -> bool:if isinstance(created_asset, UnmaterializationAsset):return True- return isinstance(created_asset, CertificationAsset) and created_asset.stopped_materialization+ return isinstance(created_asset, CertificationAsset | DeletionAsset) and created_asset.stopped_materializationdef _refuse_options_the_kind_ignores(acceptor: Acceptor, kind: WarehouseSuggestionKind, options: AcceptOptions) -> None:@@ -479,6 +534,10 @@ def _refuse_options_the_kind_ignores(acceptor: Acceptor, kind: WarehouseSuggestiraise AcceptOptionRefusedError(ignored[0], OPTION_NOT_APPLICABLE.format(kind=kind))+def _kept_the_view(suggestion: WarehouseSuggestion) -> bool:+ return "certification_id" in (suggestion.created_asset or {})++def _subject_exists(suggestion: WarehouseSuggestion) -> bool:if suggestion.subject_kind == WarehouseSuggestionSubjectKind.TABLE:return get_queryable_table(suggestion.subject_id, suggestion.team_id) is not Nonediff --git a/products/warehouse_suggestions/backend/logic/candidates/deprecate.py b/products/warehouse_suggestions/backend/logic/candidates/deprecate.pyindex d1c792edc8e1..d0b2212a36b7 100644--- a/products/warehouse_suggestions/backend/logic/candidates/deprecate.py+++ b/products/warehouse_suggestions/backend/logic/candidates/deprecate.py@@ -37,9 +37,9 @@ class DeprecateCandidate(Candidate):unread = [saved_queryfor saved_query in context.inventory.saved_queries.values()- if saved_query.materializes- and context.is_suggestible_view(saved_query)+ if context.is_suggestible_view(saved_query)and not context.is_read(_subject(saved_query))+ and not _is_done(context, saved_query)]unread_ids = [saved_query.id for saved_query in unread]dependents = dependent_saved_query_ids(context.team_id, unread_ids)@@ -57,7 +57,7 @@ class DeprecateCandidate(Candidate):if reason is not None:rejections.append(Rejection(subject=subject, reason=reason))continue- refreshes = context.reads.refreshes.get(saved_query.id)+ refreshes = context.reads.refreshes.get(saved_query.id) if saved_query.materializes else Noneseconds = refreshes.duration_ms / MILLISECONDS_PER_SECOND * context.month_scale if refreshes else 0.0read_bytes = refreshes.read_bytes * context.month_scale if refreshes else 0.0drafts.append(@@ -68,6 +68,7 @@ class DeprecateCandidate(Candidate):subject_name=saved_query.name,refresh_seconds_per_month=seconds,refresh_bytes_per_month=read_bytes,+ materialized=saved_query.materializes,),score=max(seconds / rules.seconds_floor, read_bytes / rules.bytes_floor),score_inputs={"refresh_seconds_per_month": seconds, "refresh_bytes_per_month": read_bytes},@@ -78,11 +79,13 @@ class DeprecateCandidate(Candidate):def asset_outcome(self, context: CandidateContext, subject: Subject, accepted_at: datetime | None) -> WarehouseSuggestionAssetOutcome:+ if subject.id not in context.inventory.saved_queries:+ return WarehouseSuggestionAssetOutcome.LIVEreturn certification_outcome(context, subject, CertificationStatus.DEPRECATED)def is_resolved(self, context: CandidateContext, subject: Subject) -> bool:saved_query = context.inventory.saved_queries.get(subject.id)- return saved_query is None or not saved_query.materializes or context.is_read(subject)+ return saved_query is None or context.is_read(subject) or _is_done(context, saved_query)def _rejection(self,@@ -103,5 +106,10 @@ class DeprecateCandidate(Candidate):return None+def _is_done(context: CandidateContext, saved_query: SavedQueryDefinition) -> bool:+ is_deprecated = context.inventory.certifications.get(_subject(saved_query)) == CertificationStatus.DEPRECATED+ return is_deprecated and not saved_query.materializes++def _subject(saved_query: SavedQueryDefinition) -> Subject:return Subject(kind=WarehouseSuggestionSubjectKind.SAVED_QUERY, id=saved_query.id)diff --git a/products/warehouse_suggestions/backend/logic/rules.py b/products/warehouse_suggestions/backend/logic/rules.pyindex a6b15f78415f..40a87f49e491 100644--- a/products/warehouse_suggestions/backend/logic/rules.py+++ b/products/warehouse_suggestions/backend/logic/rules.py@@ -88,6 +88,7 @@ class CertifyRules:@frozenclass DeprecateRules:min_days_with_data: int+ min_days_with_data_to_delete: intseconds_floor: floatbytes_floor: floatcounts_background_reads: bool@@ -211,7 +212,11 @@ RULES = Rules(top_share=0.10, min_users=5, min_users_floor=2, min_user_share=0.5, min_days=20, min_surfaces=2),deprecate=DeprecateRules(- min_days_with_data=30, seconds_floor=600.0, bytes_floor=float(TERABYTE), counts_background_reads=True+ min_days_with_data=27,+ min_days_with_data_to_delete=30,+ seconds_floor=600.0,+ bytes_floor=float(TERABYTE),+ counts_background_reads=True,),materialize=MaterializeRules(min_days=10,diff --git a/products/warehouse_suggestions/backend/presentation/serializers.py b/products/warehouse_suggestions/backend/presentation/serializers.pyindex 3a939f28945c..46d64e17b9a0 100644--- a/products/warehouse_suggestions/backend/presentation/serializers.py+++ b/products/warehouse_suggestions/backend/presentation/serializers.py@@ -75,6 +75,10 @@ class DeprecatePayloadSerializer(DataclassSerializer):"subject_name": {"help_text": "Name of the unread view to deprecate."},"refresh_seconds_per_month": {"help_text": "Time its refreshes take in a month, in seconds."},"refresh_bytes_per_month": {"help_text": "Bytes its refreshes read in a month."},+ "materialized": {+ "help_text": "Whether the view is materialized. A plain view has no refreshes, so both refresh "+ "costs are 0."+ },}@@ -378,4 +382,11 @@ class AcceptWarehouseSuggestionSerializer(DataclassSerializer):"By default, accepting a deprecate suggestion also stops the view's refreshes and deletes its ""stored table, unless other views or syncs depend on it.",},+ "delete_view": {+ "allow_null": False,+ "help_text": "Deprecate only: true to delete the view instead of marking it deprecated. Deleting also "+ "drops its stored table and refreshes, and cannot be undone. Refused when another view now reads it, or when "+ "it feeds person properties, account properties, a destination or a workflow. Refused with a 400 when any "+ "day in the read window has no read data, because a view read only on those days would look unread.",+ },}diff --git a/products/warehouse_suggestions/backend/tests/test_accept.py b/products/warehouse_suggestions/backend/tests/test_accept.pyindex b38eea597cbf..24dffb4754c7 100644--- a/products/warehouse_suggestions/backend/tests/test_accept.py+++ b/products/warehouse_suggestions/backend/tests/test_accept.py@@ -39,6 +39,7 @@ from products.warehouse_suggestions.backend.facade.enums import ()from products.warehouse_suggestions.backend.logic.accept import CertificationAcceptorfrom products.warehouse_suggestions.backend.logic.candidates.unmaterialize import definition_fingerprint+from products.warehouse_suggestions.backend.logic.rules import RULESfrom products.warehouse_suggestions.backend.logic.suggestions import HUMAN_TRANSITIONS, transition_tofrom products.warehouse_suggestions.backend.models import WarehouseSuggestion@@ -48,6 +49,7 @@ from .test_suggestions import make_draftFLAG = "products.warehouse_suggestions.backend.presentation.views.is_warehouse_suggestions_enabled"DAY_SECONDS = 24 * 60 * 60REPORT = "products.warehouse_suggestions.backend.logic.analytics.report_user_or_team_action"+DELETION_DEPENDENTS_CHECK = "products.data_modeling.backend.logic.saved_query_deletion.check_saved_query_deletable"DAY_KEYS = {"refresh_mode": "incremental", "incremental_key": "day", "unique_key": ["day"]}DAILY_COUNTS = "SELECT toStartOfDay(timestamp) AS day, count() AS c FROM events GROUP BY day"DAILY_COUNT_COLUMNS = {@@ -168,6 +170,11 @@ def make_the_postgres_source_direct(view: DataWarehouseSavedQuery) -> None:)+def read_a_direct_source(view: DataWarehouseSavedQuery) -> None:+ add_an_upstream_view_over_postgres(view)+ make_the_postgres_source_direct(view)++def change_the_upstream_query(view: DataWarehouseSavedQuery) -> None:DataWarehouseSavedQuery.objects.filter(team=view.team, name="orders_source").update(query={"kind": "HogQLQuery", "query": "SELECT * FROM postgres_orders WHERE 1 = 1"}@@ -236,6 +243,18 @@ class TestAcceptSuggestion(APIBaseTest):def _suggest(self, kind: WarehouseSuggestionKind) -> WarehouseSuggestion:return suggest(self.team.id, self.view.id, kind)+ def _suggest_deprecate(self, days_with_data: int = RULES.window_days) -> WarehouseSuggestion:+ draft = make_draft(fingerprint="deprecate:orders", subject_id=self.view.id)+ return ingest_surfaced(+ self.team.id,+ replace(+ draft,+ kind=WarehouseSuggestionKind.DEPRECATE,+ payload=PAYLOADS[WarehouseSuggestionKind.DEPRECATE],+ evidence={"days_with_data": days_with_data},+ ),+ )+def _suggest_materialize(self, payload: MaterializePayload) -> WarehouseSuggestion:draft = make_draft(fingerprint="materialize:orders", subject_id=self.view.id)return ingest_surfaced(self.team.id, replace(draft, kind=WarehouseSuggestionKind.MATERIALIZE, payload=payload))@@ -386,6 +405,86 @@ class TestAcceptSuggestion(APIBaseTest):properties["refresh_bytes_per_month"],) == ((True, 900, 10**9) if expect_stopped else (False, 0, 0))+ @parameterized.expand(+ [+ ("deletes_a_materialized_view", True, None, RULES.window_days, status.HTTP_200_OK),+ ("deletes_a_plain_view", False, None, RULES.window_days, status.HTTP_200_OK),+ ("refuses_when_read_data_has_gaps", True, None, RULES.window_days - 1, status.HTTP_400_BAD_REQUEST),+ (+ "refuses_when_a_view_was_built_on_it",+ True,+ add_dependent_view,+ RULES.window_days,+ status.HTTP_409_CONFLICT,+ ),+ ("refuses_when_it_feeds_a_destination", True, add_destination, RULES.window_days, status.HTTP_409_CONFLICT),+ (+ "refuses_when_it_reads_a_direct_source",+ True,+ read_a_direct_source,+ RULES.window_days,+ status.HTTP_409_CONFLICT,+ ),+ ]+ )+ def test_accepting_a_deprecate_suggestion_can_delete_the_view(+ self,+ _name: str,+ materialized: bool,+ add_reader: Callable[[DataWarehouseSavedQuery], None] | None,+ days_with_data: int,+ expected_http_status: int,+ ) -> None:+ if materialized:+ materialize_in_place(self.view)+ suggestion = self._suggest_deprecate(days_with_data)+ if add_reader is not None:+ add_reader(self.view)++ accepted = self._accept(suggestion.id, {"delete_view": True})++ deleted = expected_http_status == status.HTTP_200_OK+ self.view.refresh_from_db()+ suggestion.refresh_from_db()+ deleted_trigger = (+ ActivityLog.objects.filter(team_id=self.team.id, item_id=str(self.view.id), activity="deleted")+ .values_list("detail__trigger", flat=True)+ .first()+ )+ assert accepted["http_status"] == expected_http_status, accepted+ assert (bool(self.view.deleted), suggestion.status, self._certification_status()) == (+ deleted,+ WarehouseSuggestionStatus.ACCEPTED if deleted else WarehouseSuggestionStatus.PROPOSED,+ None,+ )+ assert suggestion.created_asset == (+ {"saved_query_id": str(self.view.id), "stopped_materialization": materialized} if deleted else None+ )+ assert deleted_trigger == (+ {"job_type": "warehouse_suggestion", "job_id": str(suggestion.id), "payload": {"kind": "deprecate"}}+ if deleted+ else None+ )++ def test_a_second_accept_cannot_turn_a_deprecation_into_a_delete(self) -> None:+ suggestion = self._suggest_deprecate()+ self._accept(suggestion.id)++ second = self._accept(suggestion.id, {"delete_view": True})++ self.view.refresh_from_db()+ assert (second["http_status"], bool(self.view.deleted)) == (status.HTTP_409_CONFLICT, False), second++ def test_delete_refuses_a_view_with_dependents_when_the_check_inside_the_delete_fails(self) -> None:+ suggestion = self._suggest_deprecate()+ add_dependent_view(self.view)++ with patch(DELETION_DEPENDENTS_CHECK, side_effect=RuntimeError("lock timeout")):+ accepted = self._accept(suggestion.id, {"delete_view": True})++ self.view.refresh_from_db()+ assert (accepted["http_status"], bool(self.view.deleted)) == (status.HTTP_409_CONFLICT, False), accepted+@parameterized.expand([("node_type_update", "products.data_modeling.backend.logic.saved_query_materialization.update_node_type"),diff --git a/products/warehouse_suggestions/backend/tests/test_candidates.py b/products/warehouse_suggestions/backend/tests/test_candidates.pyindex 9c55771f9907..4bd79a7dab78 100644--- a/products/warehouse_suggestions/backend/tests/test_candidates.py+++ b/products/warehouse_suggestions/backend/tests/test_candidates.py@@ -17,6 +17,7 @@ from products.data_catalog.backend.facade.enums import CertificationStatusfrom products.data_modeling.backend.facade.models import DAG, DataModelingJob, DataWarehouseSavedQuery, Node, NodeTypefrom products.warehouse_suggestions.backend.facade.contracts import (CertifyPayload,+ DeprecatePayload,MaterializePayload,UnmaterializePayload,)@@ -317,16 +318,82 @@ class TestMaterializeRefreshMode(BaseTest):) == (refresh_mode, incremental_key, unique_key, expected_lookback)-class TestDeprecateCandidate(SimpleTestCase):- def test_waits_for_a_full_window_of_read_data(self) -> None:- materialized = view(VIEW_ID, materializes=True)+class TestDeprecateCandidate(BaseTest):+ @parameterized.expand(+ [+ ("a_few_missing_days", 29, [VIEW_ID], None),+ ("too_many_missing_days", 26, [], "needs 27 days of read data, has 26"),+ ]+ )+ def test_waits_for_most_of_a_window_of_read_data(+ self, _name: str, days_with_data: int, expected_subjects: list, expected_skip: str | None+ ) -> None:+ candidate_context = context(+ team_reads({}, days_with_data=days_with_data),+ views=[view(VIEW_ID, materializes=True)],+ team_id=self.team.pk,+ )- result = DeprecateCandidate().evaluate(context(team_reads({}, days_with_data=29), views=[materialized]))+ result = DeprecateCandidate().evaluate(candidate_context)- assert (result.drafts, result.skipped_reason) == ((), "needs 30 days of read data, has 29")+ assert ([draft.subject_id for draft in result.drafts], result.skipped_reason) == (+ expected_subjects,+ expected_skip,+ )+ @parameterized.expand(+ [+ ("unread", None, None, [(0.0, False)], False),+ (+ "unmaterialized_during_the_window",+ None,+ SubjectRefreshes(runs=20, duration_ms=20 * 60_000, read_bytes=20 * 10**12),+ [(0.0, False)],+ False,+ ),+ ("already_deprecated", CertificationStatus.DEPRECATED, None, [], True),+ ]+ )+ def test_an_unread_plain_view(+ self,+ _name: str,+ certification: CertificationStatus | None,+ past_refreshes: SubjectRefreshes | None,+ expected_drafts: list,+ expected_resolved: bool,+ ) -> None:+ subject = view_subject(VIEW_ID)+ candidate_context = context(+ team_reads({}, refreshes={VIEW_ID: past_refreshes} if past_refreshes else None),+ views=[view(VIEW_ID)],+ certifications={subject: certification} if certification else None,+ team_id=self.team.pk,+ )++ result = DeprecateCandidate().evaluate(candidate_context)++ assert [+ (draft.score, draft.payload.materialized)+ for draft in result.drafts+ if isinstance(draft.payload, DeprecatePayload)+ ] == expected_drafts+ assert DeprecateCandidate().is_resolved(candidate_context, subject) == expected_resolved++ @parameterized.expand(+ [+ ("view_deleted", [], WarehouseSuggestionAssetOutcome.LIVE),+ ("deprecation_removed", [view(VIEW_ID)], WarehouseSuggestionAssetOutcome.DELETED),+ ]+ )+ def test_records_what_became_of_an_accepted_deprecation(+ self, _name: str, views: list, expected: WarehouseSuggestionAssetOutcome+ ) -> None:+ candidate_context = context(team_reads({}), views=views)++ assert (+ DeprecateCandidate().asset_outcome(candidate_context, view_subject(VIEW_ID), accepted_at=None) == expected+ )-class TestDeprecateBackgroundReads(BaseTest):@parameterized.expand([("background_reads_count", True, []), ("only_people_count", False, [VIEW_ID])])def test_a_view_read_only_by_background_traffic(self, _name: str, counts_background_reads: bool, expected_subjects: listdiff --git a/products/warehouse_suggestions/backend/tests/test_job.py b/products/warehouse_suggestions/backend/tests/test_job.pyindex e87f2d86f924..101b37142a13 100644--- a/products/warehouse_suggestions/backend/tests/test_job.py+++ b/products/warehouse_suggestions/backend/tests/test_job.py@@ -62,7 +62,7 @@ class TestRunTeam(ClickhouseTestMixin, BaseTest):Edge.objects.create(team=self.team, dag=dag, source=table, target=busy_node)unread, _ = self._view("old_rollup", dag, materialized=True)feeds_another, source_node = self._view("feeds_another", dag, materialized=True)- _, dependent_node = self._view("reads_feeds_another", dag)+ reads_feeds_another, dependent_node = self._view("reads_feeds_another", dag)created_today, _ = self._view("new_rollup", dag, materialized=True, created_at=NOW)Edge.objects.create(team=self.team, dag=dag, source=source_node, target=dependent_node)seed_reads(@@ -92,6 +92,7 @@ class TestRunTeam(ClickhouseTestMixin, BaseTest):(WarehouseSuggestionKind.CERTIFY, busy.id, WarehouseSuggestionStatus.PROPOSED),(WarehouseSuggestionKind.MATERIALIZE, busy.id, WarehouseSuggestionStatus.PROPOSED),(WarehouseSuggestionKind.DEPRECATE, unread.id, WarehouseSuggestionStatus.PROPOSED),+ (WarehouseSuggestionKind.DEPRECATE, reads_feeds_another.id, WarehouseSuggestionStatus.PROPOSED),])assert not (diff --git a/products/warehouse_suggestions/frontend/components/CertificationSuggestionRow.tsx b/products/warehouse_suggestions/frontend/components/CertificationSuggestionRow.tsxindex d00011ade1be..7e8dc0a1ab56 100644--- a/products/warehouse_suggestions/frontend/components/CertificationSuggestionRow.tsx+++ b/products/warehouse_suggestions/frontend/components/CertificationSuggestionRow.tsx@@ -38,6 +38,7 @@ export function CertificationSuggestionRow({ suggestion, windowDays }: Certifica? undefined: CATALOG_EDIT_ACCESS_REASON)const deprecating = isDeprecatePayload(payload)+ const refreshes = deprecating && payload.materialized !== falseconst confirmsFirst = deprecating && !isTablereturn (@@ -63,8 +64,8 @@ export function CertificationSuggestionRow({ suggestion, windowDays }: CertificawindowDays={windowDays}label={noReadsLabel(windowDays)}/>,- <span key="cost">{refreshCostLabel(payload)}</span>,- ]+ refreshes && <span key="cost">{refreshCostLabel(payload)}</span>,+ ].filter(Boolean): [<WhyThisSuggestionkey="reads"diff --git a/products/warehouse_suggestions/frontend/components/DeprecateSuggestionModal.tsx b/products/warehouse_suggestions/frontend/components/DeprecateSuggestionModal.tsxindex 39910944fc65..e5c98fd7b8f7 100644--- a/products/warehouse_suggestions/frontend/components/DeprecateSuggestionModal.tsx+++ b/products/warehouse_suggestions/frontend/components/DeprecateSuggestionModal.tsx@@ -4,10 +4,26 @@ import { LemonButton, LemonModal } from '@posthog/lemon-ui'import { LemonRadio, LemonRadioOption } from 'lib/lemon-ui/LemonRadio'-import { isDeprecatePayload, noReadsLabel, refreshCostLabel } from '../suggestionCopy'+import { deleteDisabledReason, isDeprecatePayload, noReadsLabel, refreshCostLabel } from '../suggestionCopy'import { warehouseSuggestionsLogic } from '../warehouseSuggestionsLogic'type RefreshChoice = 'stop' | 'keep'+type ActionChoice = 'deprecate' | 'delete'++const ACTION_CHOICES: LemonRadioOption<ActionChoice>[] = [+ {+ value: 'deprecate',+ label: 'Mark it deprecated',+ description: 'It stays in the data catalog with a deprecated label, so people know not to use it.',+ 'data-attr': 'warehouse-suggestions-deprecate-mark',+ },+ {+ value: 'delete',+ label: 'Delete it',+ description: "Deletes the view and its stored table. You can't undo this.",+ 'data-attr': 'warehouse-suggestions-deprecate-delete',+ },+]const REFRESH_CHOICES: LemonRadioOption<RefreshChoice>[] = [{@@ -26,21 +42,30 @@ const REFRESH_CHOICES: LemonRadioOption<RefreshChoice>[] = []export function DeprecateSuggestionModal(): JSX.Element | null {- const { acceptConfirmSuggestion, actionsInFlight, keepMaterialized, status } = useValues(warehouseSuggestionsLogic)- const { confirmAccept, closeAcceptConfirm, setKeepMaterialized } = useActions(warehouseSuggestionsLogic)+ const { acceptConfirmSuggestion, actionsInFlight, deleteView, keepMaterialized, status } =+ useValues(warehouseSuggestionsLogic)+ const { confirmAccept, closeAcceptConfirm, setDeleteView, setKeepMaterialized } =+ useActions(warehouseSuggestionsLogic)const payload = acceptConfirmSuggestion?.payloadif (!acceptConfirmSuggestion || !payload || !isDeprecatePayload(payload)) {return null}const inFlight = !!actionsInFlight[acceptConfirmSuggestion.id]+ const materialized = payload.materialized !== false+ const windowDays = status?.window_days ?? 0+ const noReads = noReadsLabel(windowDays)+ const deleteBlockedReason = deleteDisabledReason(acceptConfirmSuggestion.evidence, windowDays)+ const actionChoices = ACTION_CHOICES.map((choice) =>+ choice.value === 'delete' ? { ...choice, disabledReason: deleteBlockedReason } : choice+ )return (<LemonModalisOpenclosable={!inFlight}onClose={closeAcceptConfirm}- title={`Mark ${payload.subject_name} as deprecated?`}+ title={deleteView ? `Delete ${payload.subject_name}?` : `Mark ${payload.subject_name} as deprecated?`}footer={<><LemonButton@@ -52,29 +77,46 @@ export function DeprecateSuggestionModal(): JSX.Element | null {</LemonButton><LemonButtontype="primary"+ status={deleteView ? 'danger' : undefined}loading={inFlight}onClick={() => confirmAccept()}- data-attr="warehouse-suggestions-deprecate-confirm"+ data-attr={+ deleteView+ ? 'warehouse-suggestions-delete-confirm'+ : 'warehouse-suggestions-deprecate-confirm'+ }>- Mark deprecated+ {deleteView ? 'Delete view' : 'Mark deprecated'}</LemonButton></>}><div className="flex max-w-xl flex-col gap-4"><p className="m-0 text-sm text-secondary">- {`${noReadsLabel(status?.window_days ?? 0)}. ${refreshCostLabel(payload)}.`}+ {materialized ? `${noReads}. ${refreshCostLabel(payload)}.` : `${noReads}.`}</p><fieldset disabled={inFlight} className="flex flex-col gap-2">- <h4 className="m-0 text-sm font-semibold">Its materialization</h4>+ <h4 className="m-0 text-sm font-semibold">What to do</h4><LemonRadio- aria-label="Its materialization"- value={keepMaterialized ? 'keep' : 'stop'}- onChange={(choice) => setKeepMaterialized(choice === 'keep')}- options={REFRESH_CHOICES}+ aria-label="What to do"+ value={deleteView ? 'delete' : 'deprecate'}+ onChange={(choice) => setDeleteView(choice === 'delete')}+ options={actionChoices}radioPosition="top"/></fieldset>+ {materialized && !deleteView && (+ <fieldset disabled={inFlight} className="flex flex-col gap-2">+ <h4 className="m-0 text-sm font-semibold">Its materialization</h4>+ <LemonRadio+ aria-label="Its materialization"+ value={keepMaterialized ? 'keep' : 'stop'}+ onChange={(choice) => setKeepMaterialized(choice === 'keep')}+ options={REFRESH_CHOICES}+ radioPosition="top"+ />+ </fieldset>+ )}</div></LemonModal>)diff --git a/products/warehouse_suggestions/frontend/components/SuggestedCertificationsTable.stories.tsx b/products/warehouse_suggestions/frontend/components/SuggestedCertificationsTable.stories.tsxindex f9706fbb1835..309e96a20862 100644--- a/products/warehouse_suggestions/frontend/components/SuggestedCertificationsTable.stories.tsx+++ b/products/warehouse_suggestions/frontend/components/SuggestedCertificationsTable.stories.tsx@@ -42,6 +42,7 @@ function suggestion(human_users: kind === 'certify' ? 9 : 0,human_days: kind === 'certify' ? 28 : 0,requests_by_surface: kind === 'certify' ? { dashboard: 400, mcp: 240 } : {},+ days_with_data: 30,},evidence_window_start: '2026-09-07T00:00:00Z',evidence_window_end: '2026-10-07T00:00:00Z',@@ -66,9 +67,16 @@ interface TableStoryProps {width?: 'normal' | 'narrow'reviewOpen?: booleanconfirmSuggestionId?: string+ deleteView?: boolean}-function TableStory({ results, width, reviewOpen = false, confirmSuggestionId }: TableStoryProps): JSX.Element {+function TableStory({+ results,+ width,+ reviewOpen = false,+ confirmSuggestionId,+ deleteView = false,+}: TableStoryProps): JSX.Element {useStorybookMocks({get: {[LIST_URL]: { count: results.length, results },@@ -86,8 +94,9 @@ function TableStory({ results, width, reviewOpen = false, confirmSuggestionId }:}if (confirmSuggestionId) {logic.actions.openAcceptConfirm(confirmSuggestionId)+ logic.actions.setDeleteView(deleteView)}- }, [reviewOpen, confirmSuggestionId, stripState, logic])+ }, [reviewOpen, confirmSuggestionId, deleteView, stripState, logic])return (<div className={width === 'narrow' ? 'w-[520px] p-4' : 'w-[1000px] p-4'}><SuggestedCertificationsTable />@@ -126,6 +135,15 @@ export const ReviewDialog: Story = {suggestion('1', 'certify', 'saved_query', 'customer_monthly_revenue'),suggestion('2', 'certify', 'table', 'stripe_charges'),suggestion('3', 'deprecate', 'saved_query', 'old_marketing_rollup', false),+ {+ ...suggestion('4', 'deprecate', 'saved_query', 'signups_scratch'),+ payload: {+ subject_name: 'signups_scratch',+ refresh_seconds_per_month: 0,+ refresh_bytes_per_month: 0,+ materialized: false,+ },+ },],},parameters: dialogSnapshot(1300),@@ -150,3 +168,12 @@ export const DeprecateDialog: Story = {},parameters: dialogSnapshot(1300),}++export const DeleteDialog: Story = {+ args: {+ confirmSuggestionId: '3',+ deleteView: true,+ results: [suggestion('3', 'deprecate', 'saved_query', 'old_marketing_rollup')],+ },+ parameters: dialogSnapshot(1300),+}diff --git a/products/warehouse_suggestions/frontend/generated/api.schemas.ts b/products/warehouse_suggestions/frontend/generated/api.schemas.tsindex 04ec2b33d23b..add9182a35f2 100644--- a/products/warehouse_suggestions/frontend/generated/api.schemas.ts+++ b/products/warehouse_suggestions/frontend/generated/api.schemas.ts@@ -19,6 +19,8 @@ export interface WarehouseSuggestionDeprecatePayloadApi {refresh_seconds_per_month: number/** Bytes its refreshes read in a month. */refresh_bytes_per_month: number+ /** Whether the view is materialized. A plain view has no refreshes, so both refresh costs are 0. */+ materialized?: boolean}export interface WarehouseSuggestionVisibleSourcesApi {@@ -366,6 +368,8 @@ export interface AcceptWarehouseSuggestionApi {lookback_seconds?: number/** Deprecate only: true to keep a materialized view refreshing after it is deprecated. By default, accepting a deprecate suggestion also stops the view's refreshes and deletes its stored table, unless other views or syncs depend on it. */keep_materialized?: boolean+ /** Deprecate only: true to delete the view instead of marking it deprecated. Deleting also drops its stored table and refreshes, and cannot be undone. Refused when another view now reads it, or when it feeds person properties, account properties, a destination or a workflow. Refused with a 400 when any day in the read window has no read data, because a view read only on those days would look unread. */+ delete_view?: boolean}export interface AssignWarehouseSuggestionApi {diff --git a/products/warehouse_suggestions/frontend/generated/api.zod.ts b/products/warehouse_suggestions/frontend/generated/api.zod.tsindex 0d288c0cf6a3..cf824778996a 100644--- a/products/warehouse_suggestions/frontend/generated/api.zod.ts+++ b/products/warehouse_suggestions/frontend/generated/api.zod.ts@@ -56,6 +56,12 @@ export const WarehouseSuggestionsAcceptCreateBody = /* @__PURE__ */ zod.object({.describe("Deprecate only: true to keep a materialized view refreshing after it is deprecated. By default, accepting a deprecate suggestion also stops the view's refreshes and deletes its stored table, unless other views or syncs depend on it."),+ delete_view: zod+ .boolean()+ .optional()+ .describe(+ 'Deprecate only: true to delete the view instead of marking it deprecated. Deleting also drops its stored table and refreshes, and cannot be undone. Refused when another view now reads it, or when it feeds person properties, account properties, a destination or a workflow. Refused with a 400 when any day in the read window has no read data, because a view read only on those days would look unread.'+ ),})export const WarehouseSuggestionsAssignCreateBody = /* @__PURE__ */ zod.object({diff --git a/products/warehouse_suggestions/frontend/suggestionCopy.test.ts b/products/warehouse_suggestions/frontend/suggestionCopy.test.tsindex 2a648f852dd7..af3e62ed684e 100644--- a/products/warehouse_suggestions/frontend/suggestionCopy.test.ts+++ b/products/warehouse_suggestions/frontend/suggestionCopy.test.ts@@ -4,6 +4,7 @@ import {SavingHighlight,UNKNOWN_SOURCES_CAVEAT,dataAgeLabel,+ deleteDisabledReason,notNowCondition,savingHighlight,savingSentence,@@ -97,4 +98,11 @@ describe('suggestionCopy', () => {])('says what has to grow before a not-now %s suggestion returns', (kind, condition) => {expect(notNowCondition(kind)).toContain(condition)})++ it.each<[string, number, boolean]>([+ ['every day has read data', 30, false],+ ['a day has no read data', 29, true],+ ])('deleting is blocked when %s', (_name, daysWithData, blocked) => {+ expect(deleteDisabledReason({ days_with_data: daysWithData }, 30) !== undefined).toBe(blocked)+ })})diff --git a/products/warehouse_suggestions/frontend/suggestionCopy.ts b/products/warehouse_suggestions/frontend/suggestionCopy.tsindex 0f84b7bc2dc5..d7c170b9622a 100644--- a/products/warehouse_suggestions/frontend/suggestionCopy.ts+++ b/products/warehouse_suggestions/frontend/suggestionCopy.ts@@ -223,6 +223,13 @@ export function noReadsLabel(windowDays: number): string {return `No reads recorded in ${windowDays} days`}+export function deleteDisabledReason(evidence: WarehouseSuggestionEvidenceApi, windowDays: number): string | undefined {+ if ((evidence.days_with_data ?? 0) >= windowDays) {+ return undefined+ }+ return `Some of the last ${windowDays} days have no read data, so a view read only on those days would look unread. Mark it deprecated instead.`+}+export function refreshCostLabel(payload: Pick<WarehouseSuggestionDeprecatePayloadApi, 'refresh_seconds_per_month' | 'refresh_bytes_per_month'>): string {diff --git a/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.test.ts b/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.test.tsindex c6931df45bc1..15940bba7b3a 100644--- a/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.test.ts+++ b/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.test.ts@@ -681,19 +681,38 @@ describe('warehouseSuggestionsLogic', () => {})- it.each<[string, boolean, Record<string, unknown> | undefined, string]>([- ['stops refreshing by default', false, undefined, 'Marked old_rollup as deprecated and stopped its refreshes.'],- ['keeps refreshing when asked', true, { keep_materialized: true }, 'Marked old_rollup as deprecated.'],- ])('deprecating a materialized view %s', async (_name, keep, body, toast) => {+ it.each<[string, boolean, boolean, Record<string, unknown> | undefined, Record<string, unknown>, string]>([+ [+ 'stops refreshing by default',+ false,+ false,+ undefined,+ { certification_id: 'cert-1', stopped_materialization: true },+ 'Marked old_rollup as deprecated and stopped its refreshes.',+ ],+ [+ 'keeps refreshing when asked',+ true,+ false,+ { keep_materialized: true },+ { certification_id: 'cert-1', stopped_materialization: false },+ 'Marked old_rollup as deprecated.',+ ],+ [+ 'deletes it when asked',+ false,+ true,+ { delete_view: true },+ { saved_query_id: 'view-1', stopped_materialization: true },+ 'Deleted old_rollup.',+ ],+ ])('deprecating a materialized view %s', async (_name, keep, deleteView, body, createdAsset, toast) => {mockList.mockResolvedValue(page([DEPRECATE]))- mockAccept.mockResolvedValue({- ...DEPRECATE,- status: 'accepted',- created_asset: { certification_id: 'cert-1', stopped_materialization: !keep },- })+ mockAccept.mockResolvedValue({ ...DEPRECATE, status: 'accepted', created_asset: createdAsset })await mountLogic('catalog')logic.actions.openAcceptConfirm(DEPRECATE.id)logic.actions.setKeepMaterialized(keep)+ logic.actions.setDeleteView(deleteView)logic.actions.confirmAccept()await expectLogic(logic).toDispatchActions(['suggestionAccepted'])diff --git a/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.ts b/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.tsindex 78d5435175c2..ca16cb431189 100644--- a/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.ts+++ b/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.ts@@ -86,10 +86,14 @@ const ACCEPTED_MESSAGES: Record<string, (suggestion: WarehouseSuggestionApi) =>unmaterialize: ({ payload }) =>`Stopped materializing ${payload.subject_name}. Each read now computes it from its query.`,certify: ({ payload }) => `Certified ${payload.subject_name}.`,- deprecate: ({ payload, created_asset }) =>- created_asset?.stopped_materialization === true+ deprecate: ({ payload, created_asset }) => {+ if (created_asset?.saved_query_id) {+ return `Deleted ${payload.subject_name}.`+ }+ return created_asset?.stopped_materialization === true? `Marked ${payload.subject_name} as deprecated and stopped its refreshes.`- : `Marked ${payload.subject_name} as deprecated.`,+ : `Marked ${payload.subject_name} as deprecated.`+ },}const ACCEPT_OPTION_FIELDS = new Set(['refresh_interval_seconds',@@ -168,6 +172,19 @@ function changedRefreshOptions(return options}+function deprecateOptions(+ suggestion: WarehouseSuggestionApi,+ { deleteView, keepMaterialized }: { deleteView: boolean; keepMaterialized: boolean }+): AcceptWarehouseSuggestionApi | undefined {+ if (suggestion.kind !== 'deprecate') {+ return undefined+ }+ if (deleteView) {+ return { delete_view: true }+ }+ return keepMaterialized ? { keep_materialized: true } : undefined+}+async function fetchIncrementalCheck(viewId: string): Promise<IncrementalEligibilityApi | null> {try {const view = await warehouseSavedQueriesRetrieve(projectId(), viewId)@@ -194,6 +211,7 @@ export interface warehouseSuggestionsLogicValues {acceptConfirmSuggestion: WarehouseSuggestionApi | nullacceptConfirmSuggestionId: string | nullactionsInFlight: Record<string, boolean>+ deleteView: booleanfeatureForbidden: booleanhiddenSuggestionIds: string[]incrementalCheck: IncrementalEligibilityApi | null@@ -354,6 +372,9 @@ export interface warehouseSuggestionsLogicActions {id: stringinFlight: boolean}+ setDeleteView: (deleteView: boolean) => {+ deleteView: boolean+ }setKeepMaterialized: (keepMaterialized: boolean) => {keepMaterialized: boolean}@@ -461,6 +482,7 @@ export const warehouseSuggestionsLogic: LogicWrapper<warehouseSuggestionsLogicTycloseAcceptConfirm: true,confirmAccept: true,acceptSuggestionFailed: (id: string) => ({ id }),+ setDeleteView: (deleteView: boolean) => ({ deleteView }),setKeepMaterialized: (keepMaterialized: boolean) => ({ keepMaterialized }),setMaterializeError: (error: string | null) => ({ error }),setMaterializeInterval: (interval: DataModelingSyncInterval | null) => ({ interval }),@@ -555,6 +577,14 @@ export const warehouseSuggestionsLogic: LogicWrapper<warehouseSuggestionsLogicTycloseAcceptConfirm: () => false,},],+ deleteView: [+ false,+ {+ setDeleteView: (_, { deleteView }) => deleteView,+ openAcceptConfirm: () => false,+ closeAcceptConfirm: () => false,+ },+ ],materializeInterval: [null as DataModelingSyncInterval | null,{@@ -774,8 +804,7 @@ export const warehouseSuggestionsLogic: LogicWrapper<warehouseSuggestionsLogicTyif (!suggestion) {return}- const keepMaterialized = suggestion.kind === 'deprecate' && values.keepMaterialized- actions.acceptSuggestion(suggestion.id, keepMaterialized ? { keep_materialized: true } : undefined)+ actions.acceptSuggestion(suggestion.id, deprecateOptions(suggestion, values))},openReview: () => {posthog.capture('warehouse suggestion review opened', {diff --git a/products/warehouse_suggestions/mcp/tools.yaml b/products/warehouse_suggestions/mcp/tools.yamlindex 62e45aca0253..50c9ec882a51 100644--- a/products/warehouse_suggestions/mcp/tools.yaml+++ b/products/warehouse_suggestions/mcp/tools.yaml@@ -17,7 +17,7 @@ tools:- warehouse_view:writeannotations:readOnly: false- destructive: false+ destructive: trueidempotent: truetitle: Accept a warehouse suggestiondescription: >@@ -26,25 +26,30 @@ tools:stops its refreshes and deletes its stored table, so the view is computed when read; passkeep_materialized=true to keep it refreshing. The view stays materialized when other views read from it orits refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization`- says whether refreshes stopped. Unmaterialize suggestions turn a rarely read materialized view back into a- plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about- `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now- reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the- view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use- another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by- incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a- starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key,- unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose- with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view- changed since the suggestion was made and its suggested keys no longer apply. Requires human typed- confirmation.+ says whether refreshes stopped. A deprecate suggestion can be about a plain view too, with no refresh cost.+ Pass delete_view=true on a deprecate suggestion to delete the view instead of marking it deprecated; this+ cannot be undone. A 409 means another view, a sync, a destination or a workflow now reads from it, or it now+ reads a direct-connection source, whose reads are not logged. A 400 means some days in the read window have+ no read data, so only marking it deprecated is allowed. Unmaterialize suggestions turn a rarely read+ materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read+ computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made,+ for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn+ on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass+ refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental+ refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the+ whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds,+ refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value.+ Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and+ why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply.+ Requires human typed confirmation.confirmed_action:message: >About to accept warehouse suggestion '{id}'. This applies the change it proposes to the view or table.If it is a materialize suggestion, the view then refreshes on a schedule, which adds a recurring computecost. If it is a deprecate suggestion on a materialized view, its refreshes stop and its stored table is- deleted, unless keep_materialized is true. If it is an unmaterialize suggestion, the view's refreshes- stop, its stored table is deleted, and each read computes the view instead. Reply 'confirm' to proceed.+ deleted, unless keep_materialized is true. If delete_view is true, the view is deleted for good. If it+ is an unmaterialize suggestion, the view's refreshes stop, its stored table is deleted, and each read+ computes the view instead. Reply 'confirm' to proceed.action_label: accept warehouse suggestionwarehouse-suggestions-assign:operation: warehouse_suggestions_assign_creatediff --git a/products/warehouse_suggestions/skills/reviewing-warehouse-suggestions/SKILL.md b/products/warehouse_suggestions/skills/reviewing-warehouse-suggestions/SKILL.mdindex 7a3a503e484d..766d31cef0e1 100644--- a/products/warehouse_suggestions/skills/reviewing-warehouse-suggestions/SKILL.md+++ b/products/warehouse_suggestions/skills/reviewing-warehouse-suggestions/SKILL.md@@ -43,7 +43,10 @@ Do not invent a score or a confidence level.- Accepting stops the refreshes and deletes the stored table. The view definition stays, so it can be materialized again later.- A 409 on accept means the view changed since the suggestion was made, for example another view now reads from it. Explain the reason to the user and do not retry.- **certify**: many people read this view or table, from several places. Use the read counts in `evidence`.-- **deprecate**: nobody reads this materialized view, but it still refreshes. `refresh_seconds_per_month` and `refresh_bytes_per_month` are that cost. Accepting marks it deprecated in the data catalog, stops its refreshes and deletes its stored table. The view definition stays, so it can be materialized again later. To keep it refreshing, pass `keep_materialized: true`. After accepting, `created_asset.stopped_materialization` says whether the refreshes stopped: they keep running when other views read from it or its refreshes feed person properties, a destination or a workflow.+- **deprecate**: nobody read this view in the window.+ - When `materialized` is true, it still refreshes. `refresh_seconds_per_month` and `refresh_bytes_per_month` are that cost. When `materialized` is false, it is a plain view and costs nothing to keep. It only adds clutter.+ - Accepting marks it deprecated in the data catalog. For a materialized view, it also stops the refreshes and deletes the stored table. The view definition stays, so it can be materialized again later. To keep it refreshing, pass `keep_materialized: true`. After accepting, `created_asset.stopped_materialization` says whether the refreshes stopped: they keep running when other views read from it or its refreshes feed person properties, a destination or a workflow.+ - To delete the view instead, pass `delete_view: true`. Ask the user first, because a deleted view cannot be restored. A 409 means another view now reads from it, or it now feeds person properties, account properties, a destination or a workflow, or it now reads a direct-connection source. Explain the reason to the user and do not retry. A 400 on `delete_view` means some days in the read window have no read data. Offer to mark it deprecated instead.## 3. Change a materialize suggestion before acceptingdiff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 434bcac0eb54..eccc5e5f08a0 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -16517,7 +16517,7 @@}},"warehouse-suggestions-accept-execute": {- "description": "Step 2 of 2 for accept warehouse suggestion. Verifies the confirmation_hash from -prepare and the literal \"confirm\" string typed by the user, then performs the action. ONLY call this after the user has explicitly typed \"confirm\" in chat. Original action: Accept a proposed warehouse suggestion. Certify and deprecate suggestions mark the view or table as certified or deprecated in the data catalog. Accepting a deprecate suggestion on a materialized view also stops its refreshes and deletes its stored table, so the view is computed when read; pass keep_materialized=true to keep it refreshing. The view stays materialized when other views read from it or its refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization` says whether refreshes stopped. Unmaterialize suggestions turn a rarely read materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply. Requires human typed confirmation.",+ "description": "Step 2 of 2 for accept warehouse suggestion. Verifies the confirmation_hash from -prepare and the literal \"confirm\" string typed by the user, then performs the action. ONLY call this after the user has explicitly typed \"confirm\" in chat. Original action: Accept a proposed warehouse suggestion. Certify and deprecate suggestions mark the view or table as certified or deprecated in the data catalog. Accepting a deprecate suggestion on a materialized view also stops its refreshes and deletes its stored table, so the view is computed when read; pass keep_materialized=true to keep it refreshing. The view stays materialized when other views read from it or its refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization` says whether refreshes stopped. A deprecate suggestion can be about a plain view too, with no refresh cost. Pass delete_view=true on a deprecate suggestion to delete the view instead of marking it deprecated; this cannot be undone. A 409 means another view, a sync, a destination or a workflow now reads from it, or it now reads a direct-connection source, whose reads are not logged. A 400 means some days in the read window have no read data, so only marking it deprecated is allowed. Unmaterialize suggestions turn a rarely read materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply. Requires human typed confirmation.","category": "Warehouse suggestions","feature": "warehouse_suggestions","summary": "Accept a warehouse suggestion (execute)",@@ -16525,7 +16525,7 @@"required_scopes": ["warehouse_objects:write", "data_catalog_approval:write", "warehouse_view:write"],"api_operations": ["POST /api/projects/{project_id}/warehouse_suggestions/{id}/accept/"],"annotations": {- "destructiveHint": false,+ "destructiveHint": true,"idempotentHint": true,"openWorldHint": true,"readOnlyHint": false@@ -16533,7 +16533,7 @@"feature_flag": "warehouse-suggestions"},"warehouse-suggestions-accept-prepare": {- "description": "Step 1 of 2 for accept warehouse suggestion. Validates the arguments and returns a signed confirmation_hash plus a message to surface to the user. The user must reply with the literal word \"confirm\" before you call the matching -execute tool with the hash. Original action: Accept a proposed warehouse suggestion. Certify and deprecate suggestions mark the view or table as certified or deprecated in the data catalog. Accepting a deprecate suggestion on a materialized view also stops its refreshes and deletes its stored table, so the view is computed when read; pass keep_materialized=true to keep it refreshing. The view stays materialized when other views read from it or its refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization` says whether refreshes stopped. Unmaterialize suggestions turn a rarely read materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply. Requires human typed confirmation.",+ "description": "Step 1 of 2 for accept warehouse suggestion. Validates the arguments and returns a signed confirmation_hash plus a message to surface to the user. The user must reply with the literal word \"confirm\" before you call the matching -execute tool with the hash. Original action: Accept a proposed warehouse suggestion. Certify and deprecate suggestions mark the view or table as certified or deprecated in the data catalog. Accepting a deprecate suggestion on a materialized view also stops its refreshes and deletes its stored table, so the view is computed when read; pass keep_materialized=true to keep it refreshing. The view stays materialized when other views read from it or its refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization` says whether refreshes stopped. A deprecate suggestion can be about a plain view too, with no refresh cost. Pass delete_view=true on a deprecate suggestion to delete the view instead of marking it deprecated; this cannot be undone. A 409 means another view, a sync, a destination or a workflow now reads from it, or it now reads a direct-connection source, whose reads are not logged. A 400 means some days in the read window have no read data, so only marking it deprecated is allowed. Unmaterialize suggestions turn a rarely read materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply. Requires human typed confirmation.","category": "Warehouse suggestions","feature": "warehouse_suggestions","summary": "Accept a warehouse suggestion (prepare)",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 8eaef8eb5aa9..9aea9abeab1a 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -17291,7 +17291,7 @@}},"warehouse-suggestions-accept-execute": {- "description": "Step 2 of 2 for accept warehouse suggestion. Verifies the confirmation_hash from -prepare and the literal \"confirm\" string typed by the user, then performs the action. ONLY call this after the user has explicitly typed \"confirm\" in chat. Original action: Accept a proposed warehouse suggestion. Certify and deprecate suggestions mark the view or table as certified or deprecated in the data catalog. Accepting a deprecate suggestion on a materialized view also stops its refreshes and deletes its stored table, so the view is computed when read; pass keep_materialized=true to keep it refreshing. The view stays materialized when other views read from it or its refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization` says whether refreshes stopped. Unmaterialize suggestions turn a rarely read materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply. Requires human typed confirmation.",+ "description": "Step 2 of 2 for accept warehouse suggestion. Verifies the confirmation_hash from -prepare and the literal \"confirm\" string typed by the user, then performs the action. ONLY call this after the user has explicitly typed \"confirm\" in chat. Original action: Accept a proposed warehouse suggestion. Certify and deprecate suggestions mark the view or table as certified or deprecated in the data catalog. Accepting a deprecate suggestion on a materialized view also stops its refreshes and deletes its stored table, so the view is computed when read; pass keep_materialized=true to keep it refreshing. The view stays materialized when other views read from it or its refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization` says whether refreshes stopped. A deprecate suggestion can be about a plain view too, with no refresh cost. Pass delete_view=true on a deprecate suggestion to delete the view instead of marking it deprecated; this cannot be undone. A 409 means another view, a sync, a destination or a workflow now reads from it, or it now reads a direct-connection source, whose reads are not logged. A 400 means some days in the read window have no read data, so only marking it deprecated is allowed. Unmaterialize suggestions turn a rarely read materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply. Requires human typed confirmation.","category": "Warehouse suggestions","feature": "warehouse_suggestions","summary": "Accept a warehouse suggestion (execute)",@@ -17299,7 +17299,7 @@"required_scopes": ["warehouse_objects:write", "data_catalog_approval:write", "warehouse_view:write"],"api_operations": ["POST /api/projects/{project_id}/warehouse_suggestions/{id}/accept/"],"annotations": {- "destructiveHint": false,+ "destructiveHint": true,"idempotentHint": true,"openWorldHint": true,"readOnlyHint": false@@ -17307,7 +17307,7 @@"feature_flag": "warehouse-suggestions"},"warehouse-suggestions-accept-prepare": {- "description": "Step 1 of 2 for accept warehouse suggestion. Validates the arguments and returns a signed confirmation_hash plus a message to surface to the user. The user must reply with the literal word \"confirm\" before you call the matching -execute tool with the hash. Original action: Accept a proposed warehouse suggestion. Certify and deprecate suggestions mark the view or table as certified or deprecated in the data catalog. Accepting a deprecate suggestion on a materialized view also stops its refreshes and deletes its stored table, so the view is computed when read; pass keep_materialized=true to keep it refreshing. The view stays materialized when other views read from it or its refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization` says whether refreshes stopped. Unmaterialize suggestions turn a rarely read materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply. Requires human typed confirmation.",+ "description": "Step 1 of 2 for accept warehouse suggestion. Validates the arguments and returns a signed confirmation_hash plus a message to surface to the user. The user must reply with the literal word \"confirm\" before you call the matching -execute tool with the hash. Original action: Accept a proposed warehouse suggestion. Certify and deprecate suggestions mark the view or table as certified or deprecated in the data catalog. Accepting a deprecate suggestion on a materialized view also stops its refreshes and deletes its stored table, so the view is computed when read; pass keep_materialized=true to keep it refreshing. The view stays materialized when other views read from it or its refreshes feed person properties, a destination or a workflow; `created_asset.stopped_materialization` says whether refreshes stopped. A deprecate suggestion can be about a plain view too, with no refresh cost. Pass delete_view=true on a deprecate suggestion to delete the view instead of marking it deprecated; this cannot be undone. A 409 means another view, a sync, a destination or a workflow now reads from it, or it now reads a direct-connection source, whose reads are not logged. A 400 means some days in the read window have no read data, so only marking it deprecated is allowed. Unmaterialize suggestions turn a rarely read materialized view back into a plain view: its refreshes stop, its stored table is deleted, and each read computes the view, taking about `read_seconds`. A 409 means the view changed since the suggestion was made, for example another view now reads from it or it now refreshes incrementally. Materialize suggestions turn on materialization for the view on the proposed schedule, which adds a recurring compute cost; pass refresh_interval_seconds to use another schedule. They also apply the payload's refresh_mode: incremental refreshes read only new rows by incremental_key and update rows by unique_key, full refreshes rebuild the whole table. The payload is a starting point. To change it, pass any of refresh_interval_seconds, refresh_mode, incremental_key, unique_key and lookback_seconds; an omitted field keeps the suggested value. Check keys the person chose with view-check-incremental first. A 400 names the field the server refused and why. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply. Requires human typed confirmation.","category": "Warehouse suggestions","feature": "warehouse_suggestions","summary": "Accept a warehouse suggestion (prepare)",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 89b706d0573a..b8b40b491e6d 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -577,6 +577,8 @@ export namespace Schemas {lookback_seconds?: number;/** Deprecate only: true to keep a materialized view refreshing after it is deprecated. By default, accepting a deprecate suggestion also stops the view's refreshes and deletes its stored table, unless other views or syncs depend on it. */keep_materialized?: boolean;+ /** Deprecate only: true to delete the view instead of marking it deprecated. Deleting also drops its stored table and refreshes, and cannot be undone. Refused when another view now reads it, or when it feeds person properties, account properties, a destination or a workflow. Refused with a 400 when any day in the read window has no read data, because a view read only on those days would look unread. */+ delete_view?: boolean;}export interface AccessControlResourceDefault {@@ -85130,6 +85132,8 @@ export namespace Schemas {refresh_seconds_per_month: number;/** Bytes its refreshes read in a month. */refresh_bytes_per_month: number;+ /** Whether the view is materialized. A plain view has no refreshes, so both refresh costs are 0. */+ materialized?: boolean;}export interface WarehouseSuggestionVisibleSources {diff --git a/services/mcp/src/generated/warehouse_suggestions/api.ts b/services/mcp/src/generated/warehouse_suggestions/api.tsindex 2ee3cca48a14..1615074eaaaa 100644--- a/services/mcp/src/generated/warehouse_suggestions/api.ts+++ b/services/mcp/src/generated/warehouse_suggestions/api.ts@@ -114,6 +114,12 @@ export const WarehouseSuggestionsAcceptCreateBody = () => zod.object({.describe("Deprecate only: true to keep a materialized view refreshing after it is deprecated. By default, accepting a deprecate suggestion also stops the view's refreshes and deletes its stored table, unless other views or syncs depend on it."),+ delete_view: zod+ .boolean()+ .optional()+ .describe(+ 'Deprecate only: true to delete the view instead of marking it deprecated. Deleting also drops its stored table and refreshes, and cannot be undone. Refused when another view now reads it, or when it feeds person properties, account properties, a destination or a workflow. Refused with a 400 when any day in the read window has no read data, because a view read only on those days would look unread.'+ ),})export const warehouseSuggestionsAssignCreatePathIdRegExp = new RegExp(diff --git a/services/mcp/src/tools/generated/warehouse_suggestions.ts b/services/mcp/src/tools/generated/warehouse_suggestions.tsindex c112e12ab2ff..f694591c1119 100644--- a/services/mcp/src/tools/generated/warehouse_suggestions.ts+++ b/services/mcp/src/tools/generated/warehouse_suggestions.ts@@ -41,7 +41,7 @@ const warehouseSuggestionsAcceptPrepare = (): ToolBase<purpose: 'warehouse-suggestions-accept',actionLabel: 'accept warehouse suggestion',messageTemplate:- "About to accept warehouse suggestion '{id}'. This applies the change it proposes to the view or table. If it is a materialize suggestion, the view then refreshes on a schedule, which adds a recurring compute cost. If it is a deprecate suggestion on a materialized view, its refreshes stop and its stored table is deleted, unless keep_materialized is true. If it is an unmaterialize suggestion, the view's refreshes stop, its stored table is deleted, and each read computes the view instead. Reply 'confirm' to proceed.\n",+ "About to accept warehouse suggestion '{id}'. This applies the change it proposes to the view or table. If it is a materialize suggestion, the view then refreshes on a schedule, which adds a recurring compute cost. If it is a deprecate suggestion on a materialized view, its refreshes stop and its stored table is deleted, unless keep_materialized is true. If delete_view is true, the view is deleted for good. If it is an unmaterialize suggestion, the view's refreshes stop, its stored table is deleted, and each read computes the view instead. Reply 'confirm' to proceed.\n",codec: __runtime.codec,stash: __runtime.stash,boundScope: { projectId: String(__scopeProjectId) },@@ -93,6 +93,9 @@ const warehouseSuggestionsAcceptExecute = (): ToolBase<if (params.keep_materialized !== undefined) {body['keep_materialized'] = params.keep_materialized}+ if (params.delete_view !== undefined) {+ body['delete_view'] = params.delete_view+ }const result = await context.api.request<Schemas.WarehouseSuggestion>({method: 'POST',path: `/api/projects/${encodeURIComponent(String(projectId))}/warehouse_suggestions/${encodeURIComponent(String(params.id))}/accept/`,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/warehouse-suggestions-accept-prepare.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/warehouse-suggestions-accept-prepare.jsonindex 477b0a7f3521..02cd4bc67d4e 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/warehouse-suggestions-accept-prepare.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/warehouse-suggestions-accept-prepare.json@@ -1,6 +1,10 @@{"$schema": "https://json-schema.org/draft/2020-12/schema","properties": {+ "delete_view": {+ "description": "Deprecate only: true to delete the view instead of marking it deprecated. Deleting also drops its stored table and refreshes, and cannot be undone. Refused when another view now reads it, or when it feeds person properties, account properties, a destination or a workflow. Refused with a 400 when any day in the read window has no read data, because a view read only on those days would look unread.",+ "type": "boolean"+ },"id": {"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$","type": "string"