Skip to content

: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.

feat(data-catalog): show certification badges on SQL editor tables (#74255)

Thiago Salvatoreecada6acaac2
diff --git a/frontend/src/products.tsx b/frontend/src/products.tsx
index 65646331a573..4a54d87e9036 100644
--- a/frontend/src/products.tsx
+++ b/frontend/src/products.tsx
@@ -1800,6 +1800,7 @@ export const getTreeItemsProducts = (): FileSystemImport[] => [
iconType: 'data_warehouse',
href: urls.dataCatalog(),
flag: FEATURE_FLAGS.PRODUCT_DATA_CATALOG,
+ tags: ['alpha'],
sceneKey: 'DataCatalog',
sceneKeys: ['DataCatalog', 'DataCatalogMetric'],
},
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 2bc2b921af9b..bd7f8cf3ad6d 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -17271,6 +17271,10 @@
"DatabaseSchemaBatchExportTable": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
@@ -17297,6 +17301,10 @@
"DatabaseSchemaDataWarehouseTable": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
@@ -17344,6 +17352,10 @@
"DatabaseSchemaEndpointTable": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
@@ -17420,6 +17432,10 @@
"DatabaseSchemaManagedViewTable": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
@@ -17466,6 +17482,10 @@
"DatabaseSchemaMaterializedViewTable": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
@@ -17501,6 +17521,10 @@
"DatabaseSchemaPostHogTable": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
@@ -17625,6 +17649,10 @@
"DatabaseSchemaSystemTable": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
@@ -17676,9 +17704,37 @@
}
]
},
+ "DatabaseSchemaTableCertification": {
+ "additionalProperties": false,
+ "properties": {
+ "certified_at": {
+ "type": "string"
+ },
+ "certified_by": {
+ "type": "string"
+ },
+ "notes": {
+ "type": "string"
+ },
+ "status": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertificationStatus",
+ "description": "Settled data catalog trust mark: 'certified' (prefer this source) or 'deprecated' (avoid it)."
+ }
+ },
+ "required": ["status"],
+ "type": "object"
+ },
+ "DatabaseSchemaTableCertificationStatus": {
+ "enum": ["certified", "deprecated"],
+ "type": "string"
+ },
"DatabaseSchemaTableCommon": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
@@ -17717,6 +17773,10 @@
"DatabaseSchemaViewTable": {
"additionalProperties": false,
"properties": {
+ "certification": {
+ "$ref": "#/definitions/DatabaseSchemaTableCertification",
+ "description": "Present only when the table or view carries a settled data catalog certification."
+ },
"fields": {
"additionalProperties": {
"$ref": "#/definitions/DatabaseSchemaField"
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index f059f3ec2706..bb0b506ed4bd 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -5080,12 +5080,24 @@ export type DatabaseSchemaTableType =
| 'managed_view'
| 'endpoint'
+export type DatabaseSchemaTableCertificationStatus = 'certified' | 'deprecated'
+
+export interface DatabaseSchemaTableCertification {
+ /** Settled data catalog trust mark: 'certified' (prefer this source) or 'deprecated' (avoid it). */
+ status: DatabaseSchemaTableCertificationStatus
+ notes?: string
+ certified_by?: string
+ certified_at?: string
+}
+
export interface DatabaseSchemaTableCommon {
type: DatabaseSchemaTableType
id: string
name: string
fields: Record<string, DatabaseSchemaField>
row_count?: number
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification
}
export interface DatabaseSchemaViewTable extends DatabaseSchemaTableCommon {
diff --git a/frontend/src/scenes/data-warehouse/TableCertificationBadge.tsx b/frontend/src/scenes/data-warehouse/TableCertificationBadge.tsx
new file mode 100644
index 000000000000..0d1b419b31ca
--- /dev/null
+++ b/frontend/src/scenes/data-warehouse/TableCertificationBadge.tsx
@@ -0,0 +1,66 @@
+import { IconCheckCircle, IconWarning } from '@posthog/icons'
+
+import { LemonTag } from 'lib/lemon-ui/LemonTag'
+import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { humanFriendlyDetailedTime } from 'lib/utils/datetime'
+
+import { DatabaseSchemaTableCertification } from '~/queries/schema/schema-general'
+
+const STATUS_COPY: Record<DatabaseSchemaTableCertification['status'], { label: string; guidance: string }> = {
+ certified: { label: 'Certified', guidance: 'Prefer this source.' },
+ deprecated: { label: 'Deprecated', guidance: 'Avoid this source.' },
+}
+
+function certificationTooltip(certification: DatabaseSchemaTableCertification): JSX.Element {
+ const { label, guidance } = STATUS_COPY[certification.status]
+ return (
+ <div className="flex flex-col gap-1">
+ <span>
+ {label}. {guidance}
+ </span>
+ {certification.notes ? <span>{certification.notes}</span> : null}
+ {certification.certified_by ? (
+ <span className="text-secondary">
+ {label} by {certification.certified_by}
+ {certification.certified_at ? ` (${humanFriendlyDetailedTime(certification.certified_at)})` : ''}
+ </span>
+ ) : null}
+ </div>
+ )
+}
+
+export function TableCertificationIcon({
+ certification,
+}: {
+ certification?: DatabaseSchemaTableCertification | null
+}): JSX.Element | null {
+ if (!certification) {
+ return null
+ }
+ return (
+ <Tooltip title={certificationTooltip(certification)}>
+ {certification.status === 'certified' ? (
+ <IconCheckCircle className="shrink-0 text-success" />
+ ) : (
+ <IconWarning className="shrink-0 text-warning" />
+ )}
+ </Tooltip>
+ )
+}
+
+export function TableCertificationTag({
+ certification,
+}: {
+ certification?: DatabaseSchemaTableCertification | null
+}): JSX.Element | null {
+ if (!certification) {
+ return null
+ }
+ return (
+ <Tooltip title={certificationTooltip(certification)}>
+ <LemonTag type={certification.status === 'certified' ? 'success' : 'warning'}>
+ {STATUS_COPY[certification.status].label}
+ </LemonTag>
+ </Tooltip>
+ )
+}
diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx
index d80cb776e3bd..795839570185 100644
--- a/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx
@@ -52,6 +52,7 @@ import { sourceManagementLogic } from 'products/data_warehouse/frontend/shared/l
import { buildSelectAllQuery } from 'products/data_warehouse/frontend/utils'
import { dataWarehouseViewsLogic } from '../../saved_queries/dataWarehouseViewsLogic'
+import { TableCertificationIcon } from '../../TableCertificationBadge'
import { draftsLogic } from '../draftsLogic'
import { renderTableCount } from '../editorSceneLogic'
import { isJoined, queryDatabaseLogic } from './queryDatabaseLogic'
@@ -414,6 +415,12 @@ export const QueryDatabase = ({
const isColumn = item.record?.type === 'column'
const columnType = isColumn ? item.record?.field?.type : null
const tableKindLabel = !isColumn && item.children?.length ? getTableKindLabel(item) : null
+ const certification =
+ item.record?.type === 'table'
+ ? item.record?.table?.certification
+ : item.record?.type === 'view'
+ ? item.record?.certification
+ : undefined
const itemLabel = typeof item.displayName === 'string' ? item.displayName : item.name
const isHighlightedFolderDropTarget =
item.record?.type === 'folder' &&
@@ -460,6 +467,7 @@ export const QueryDatabase = ({
{item.displayName ?? item.name}
</span>
)}
+ <TableCertificationIcon certification={certification} />
{isColumn && columnType ? (
<span className="shrink rounded px-1.5 py-0.5 text-xs text-muted-alt">
{columnType === 'field_traverser' && item?.record?.field.chain
diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
index e45bc85f560d..c17bb214dad2 100644
--- a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
@@ -912,6 +912,7 @@ const createViewNode = (
type: 'view',
view: view,
isSavedQuery: !isManagedView,
+ certification: schemaTable?.certification,
...(matches && { searchMatches: matches }),
},
children: viewChildren,
diff --git a/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx b/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx
index 6f269a67847e..34b0a195c68e 100644
--- a/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx
+++ b/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx
@@ -20,6 +20,7 @@ import {
DataWarehouseSavedQueryRunHistory,
} from '~/types'
+import { TableCertificationTag } from '../TableCertificationBadge'
import { PAGE_SIZE, viewsTabLogic } from './viewsTabLogic'
const getDisabledReason = (view: DataWarehouseSavedQuery): string | undefined => {
@@ -99,6 +100,7 @@ export function ViewsTab({ getViewUrl }: ViewsTabProps = {}): JSX.Element {
accessControlModalOpen,
editingAccessControlView,
featureFlags,
+ viewsMapById,
} = useValues(viewsTabLogic)
const {
setSearchTerm,
@@ -112,6 +114,13 @@ export function ViewsTab({ getViewUrl }: ViewsTabProps = {}): JSX.Element {
const warehouseAccessControlEnabled = !!featureFlags[FEATURE_FLAGS.HOGQL_WAREHOUSE_ACCESS_CONTROL]
+ const nameWithCertification = (view: DataWarehouseSavedQuery, content: JSX.Element): JSX.Element => (
+ <div className="flex items-center gap-2">
+ <div>{content}</div>
+ <TableCertificationTag certification={viewsMapById[view.id]?.certification} />
+ </div>
+ )
+
const accessControlMenuButton = (view: DataWarehouseSavedQuery): JSX.Element | null => {
if (!warehouseAccessControlEnabled || view.managed_viewset_kind !== null) {
return null
@@ -158,44 +167,50 @@ export function ViewsTab({ getViewUrl }: ViewsTabProps = {}): JSX.Element {
title: 'Name',
key: 'name',
render: (_, view: DataWarehouseSavedQuery) =>
- view.managed_viewset_kind !== null ? (
- <>
- <Tooltip
- interactive
- title={
- <>
- You cannot edit the definition for a view that belongs to a
- managed viewset. You can enable/disable the viewset in the{' '}
- <Link to={urls.dataWarehouseManagedViewsets()}>
- Managed Viewsets
- </Link>{' '}
- page.
- </>
- }
- >
- <span className="font-bold text-primary">{view.name}</span>
- </Tooltip>
- <br />
- <span className="text-muted text-xs">
- Created by the{' '}
- <Link to={urls.dataWarehouseManagedViewsets()} className="text-muted">
- <code>{view.managed_viewset_kind}</code>
- </Link>{' '}
- managed viewset
- </span>
- </>
- ) : view.origin === DataWarehouseSavedQueryOrigin.ENDPOINT ? (
- <LemonTableLink
- to={urls.endpoint(view.name)}
- title={view.name}
- description={`Created by the ${view.name} endpoint.`}
- />
- ) : (
- <LemonTableLink
- to={getViewUrl?.(view) ?? urls.sqlEditor({ view_id: view.id })}
- title={view.name}
- description="Materialized view"
- />
+ nameWithCertification(
+ view,
+ view.managed_viewset_kind !== null ? (
+ <>
+ <Tooltip
+ interactive
+ title={
+ <>
+ You cannot edit the definition for a view that belongs to a
+ managed viewset. You can enable/disable the viewset in the{' '}
+ <Link to={urls.dataWarehouseManagedViewsets()}>
+ Managed Viewsets
+ </Link>{' '}
+ page.
+ </>
+ }
+ >
+ <span className="font-bold text-primary">{view.name}</span>
+ </Tooltip>
+ <br />
+ <span className="text-muted text-xs">
+ Created by the{' '}
+ <Link
+ to={urls.dataWarehouseManagedViewsets()}
+ className="text-muted"
+ >
+ <code>{view.managed_viewset_kind}</code>
+ </Link>{' '}
+ managed viewset
+ </span>
+ </>
+ ) : view.origin === DataWarehouseSavedQueryOrigin.ENDPOINT ? (
+ <LemonTableLink
+ to={urls.endpoint(view.name)}
+ title={view.name}
+ description={`Created by the ${view.name} endpoint.`}
+ />
+ ) : (
+ <LemonTableLink
+ to={getViewUrl?.(view) ?? urls.sqlEditor({ view_id: view.id })}
+ title={view.name}
+ description="Materialized view"
+ />
+ )
),
},
{
@@ -333,37 +348,43 @@ export function ViewsTab({ getViewUrl }: ViewsTabProps = {}): JSX.Element {
title: 'Name',
key: 'name',
render: (_, view: DataWarehouseSavedQuery) =>
- view.managed_viewset_kind !== null ? (
- <>
- <Tooltip
- interactive
- title={
- <>
- You cannot edit the definition for a view that belongs to a
- managed viewset. You can enable/disable the viewset in the{' '}
- <Link to={urls.dataWarehouseManagedViewsets()}>
- Managed Viewsets
- </Link>{' '}
- page.
- </>
- }
- >
- <span className="font-bold text-primary">{view.name}</span>
- </Tooltip>
- <br />
- <span className="text-muted text-xs">
- Created by the{' '}
- <Link to={urls.dataWarehouseManagedViewsets()} className="text-muted">
- <code>{view.managed_viewset_kind}</code>
- </Link>{' '}
- managed viewset
- </span>
- </>
- ) : (
- <LemonTableLink
- to={getViewUrl?.(view) ?? urls.sqlEditor({ view_id: view.id })}
- title={view.name}
- />
+ nameWithCertification(
+ view,
+ view.managed_viewset_kind !== null ? (
+ <>
+ <Tooltip
+ interactive
+ title={
+ <>
+ You cannot edit the definition for a view that belongs to a
+ managed viewset. You can enable/disable the viewset in the{' '}
+ <Link to={urls.dataWarehouseManagedViewsets()}>
+ Managed Viewsets
+ </Link>{' '}
+ page.
+ </>
+ }
+ >
+ <span className="font-bold text-primary">{view.name}</span>
+ </Tooltip>
+ <br />
+ <span className="text-muted text-xs">
+ Created by the{' '}
+ <Link
+ to={urls.dataWarehouseManagedViewsets()}
+ className="text-muted"
+ >
+ <code>{view.managed_viewset_kind}</code>
+ </Link>{' '}
+ managed viewset
+ </span>
+ </>
+ ) : (
+ <LemonTableLink
+ to={getViewUrl?.(view) ?? urls.sqlEditor({ view_id: view.id })}
+ title={view.name}
+ />
+ )
),
},
{
diff --git a/frontend/src/scenes/data-warehouse/scene/viewsTabLogic.ts b/frontend/src/scenes/data-warehouse/scene/viewsTabLogic.ts
index 6daaac65f263..5d4fdf80b5bc 100644
--- a/frontend/src/scenes/data-warehouse/scene/viewsTabLogic.ts
+++ b/frontend/src/scenes/data-warehouse/scene/viewsTabLogic.ts
@@ -6,6 +6,7 @@ import { LemonDialog } from '@posthog/lemon-ui'
import api from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
import {
DataWarehouseSavedQuery,
@@ -14,6 +15,12 @@ import {
} from '~/types'
import type { FeatureFlagsSet } from '../../../lib/logic/featureFlagLogic'
+import type {
+ DatabaseSchemaEndpointTable,
+ DatabaseSchemaManagedViewTable,
+ DatabaseSchemaQueryResponse,
+ DatabaseSchemaViewTable,
+} from '../../../queries/schema/schema-general'
import { dataWarehouseViewsLogic } from '../saved_queries/dataWarehouseViewsLogic'
export const PAGE_SIZE = 10
@@ -22,6 +29,8 @@ export const PAGE_SIZE = 10
export interface viewsTabLogicValues {
dataWarehouseSavedQueries: DataWarehouseSavedQuery[] // dataWarehouseViewsLogic
dataWarehouseSavedQueriesLoading: boolean // dataWarehouseViewsLogic
+ database: Required<DatabaseSchemaQueryResponse> | null // databaseTableListLogic
+ viewsMapById: Record<string, DatabaseSchemaEndpointTable | DatabaseSchemaManagedViewTable | DatabaseSchemaViewTable> // databaseTableListLogic
featureFlags: FeatureFlagsSet // featureFlagLogic
accessControlModalOpen: boolean
editingAccessControlView: DataWarehouseSavedQuery | null
@@ -49,6 +58,15 @@ export interface viewsTabLogicActions {
runDataWarehouseSavedQuery: (viewId: string) => {
viewId: string
} // dataWarehouseViewsLogic
+ loadDatabase: (
+ args_0?:
+ | {
+ force?: boolean
+ }
+ | undefined
+ ) => {
+ force?: boolean
+ } // databaseTableListLogic
closeAccessControlModal: () => {
value: true
}
@@ -179,8 +197,15 @@ export const viewsTabLogic = kea<viewsTabLogicType>([
['dataWarehouseSavedQueries', 'dataWarehouseSavedQueriesLoading'],
featureFlagLogic,
['featureFlags'],
+ databaseTableListLogic,
+ ['database', 'viewsMapById'],
+ ],
+ actions: [
+ dataWarehouseViewsLogic,
+ ['deleteDataWarehouseSavedQuery', 'runDataWarehouseSavedQuery'],
+ databaseTableListLogic,
+ ['loadDatabase'],
],
- actions: [dataWarehouseViewsLogic, ['deleteDataWarehouseSavedQuery', 'runDataWarehouseSavedQuery']],
})),
actions({
setSearchTerm: (searchTerm: string) => ({ searchTerm }),
@@ -454,5 +479,9 @@ export const viewsTabLogic = kea<viewsTabLogicType>([
if (values.dataWarehouseSavedQueries.length > 0) {
actions.loadVisibleData()
}
+ // Certification badges come from the schema response; reuse it when already loaded
+ if (!values.database) {
+ actions.loadDatabase()
+ }
}),
])
diff --git a/frontend/src/scenes/insights/EditorFilters/funnelDataWarehouseStepDefinitionPopoverLogic.ts b/frontend/src/scenes/insights/EditorFilters/funnelDataWarehouseStepDefinitionPopoverLogic.ts
index cb3ff53bb42e..6ddaf097586f 100644
--- a/frontend/src/scenes/insights/EditorFilters/funnelDataWarehouseStepDefinitionPopoverLogic.ts
+++ b/frontend/src/scenes/insights/EditorFilters/funnelDataWarehouseStepDefinitionPopoverLogic.ts
@@ -23,6 +23,7 @@ import type {
DatabaseSchemaSource,
FunnelsQuery,
} from '../../../queries/schema/schema-general'
+import type { DatabaseSchemaTableCertification } from '../../../queries/schema/schema-general'
export type FunnelFieldKey = 'id_field' | 'timestamp_field' | 'aggregation_target_field'
@@ -81,6 +82,7 @@ export interface funnelDataWarehouseStepDefinitionPopoverLogicValues {
previewSelectedKey: string | undefined
previewTable: {
aggregation_target_field?: string | undefined
+ certification?: DatabaseSchemaTableCertification | undefined
distinct_id_field?: string | undefined
fields: {
[k: string]: DatabaseSchemaField
@@ -148,6 +150,7 @@ export interface funnelDataWarehouseStepDefinitionPopoverLogicMeta {
) => string | undefined
previewTable: (table: DataWarehouseTableForInsight) => {
aggregation_target_field?: string | undefined
+ certification?: DatabaseSchemaTableCertification | undefined
distinct_id_field?: string | undefined
fields: {
[k: string]: DatabaseSchemaField
diff --git a/posthog/hogql/database/database.py b/posthog/hogql/database/database.py
index 11c6b6268b68..1b8975b05487 100644
--- a/posthog/hogql/database/database.py
+++ b/posthog/hogql/database/database.py
@@ -164,6 +164,7 @@ if TYPE_CHECKING:
DatabaseSchemaManagedViewTable,
DatabaseSchemaPostHogTable,
DatabaseSchemaSystemTable,
+ DatabaseSchemaTableCertification,
DatabaseSchemaViewTable,
DataWarehouseSyncWarning,
HogQLQueryModifiers,
@@ -858,6 +859,8 @@ class Database(BaseModel):
if context.team_id is None:
raise ResolutionError("Must provide team_id to serialize database")
+ certifications_by_table_id, certifications_by_saved_query_id = _settled_catalog_certifications(context)
+
# PostHog tables
posthog_table_names = (
[]
@@ -1005,6 +1008,7 @@ class Database(BaseModel):
schema=schema,
source=source,
row_count=warehouse_table.row_count,
+ certification=certifications_by_table_id.get(str(warehouse_table.id)),
)
except (QueryError, ResolutionError) as e:
logger.warning(
@@ -1130,6 +1134,7 @@ class Database(BaseModel):
query=HogQLQuery(query=saved_query.query["query"]), # type: ignore[index]
row_count=row_count,
status=saved_query.status,
+ certification=certifications_by_saved_query_id.get(str(saved_query.pk)),
)
continue
@@ -1139,6 +1144,7 @@ class Database(BaseModel):
name=view_name,
query=HogQLQuery(query=saved_query.query["query"]), # type: ignore[index]
row_count=row_count,
+ certification=certifications_by_saved_query_id.get(str(saved_query.pk)),
)
return tables
@@ -2506,6 +2512,59 @@ def _schema_field_input(table: Table) -> dict[str, Any]:
return field_input
+def _settled_catalog_certifications(
+ context: HogQLContext,
+) -> tuple[dict[str, DatabaseSchemaTableCertification], dict[str, DatabaseSchemaTableCertification]]:
+ """Settled (certified/deprecated) catalog marks for the team as `(by_table_id, by_saved_query_id)`.
+
+ One bulk query keyed by target id — `(team, name)` is not unique on `DataWarehouseTable`, so a
+ name-keyed lookup could let one table's mark clobber another's. Gated on the product flag and on
+ data_catalog read access like `information_schema`, and fail-soft: certification must never break
+ schema serialization. Contexts without a `team` object (e.g. the AI schema path) skip the flag
+ evaluation and get no marks rather than paying a Team fetch.
+ """
+ from posthog.schema import DatabaseSchemaTableCertification # noqa: PLC0415
+
+ from posthog.hogql.database.schema.information_schema import _can_read_catalog # noqa: PLC0415
+
+ team = context.team
+ team_id = context.team_id
+
+ try:
+ from products.data_catalog.backend.facade.enums import CertificationStatus # noqa: PLC0415
+ from products.data_catalog.backend.facade.flags import is_data_catalog_enabled # noqa: PLC0415
+ from products.data_catalog.backend.facade.models import TableCertification # noqa: PLC0415
+
+ if team is None or team_id is None or not is_data_catalog_enabled(team) or not _can_read_catalog(context):
+ return {}, {}
+
+ by_table_id: dict[str, DatabaseSchemaTableCertification] = {}
+ by_saved_query_id: dict[str, DatabaseSchemaTableCertification] = {}
+ certifications = (
+ TableCertification.objects.for_team(team_id)
+ .filter(status__in=(CertificationStatus.CERTIFIED, CertificationStatus.DEPRECATED))
+ .exclude(table__deleted=True)
+ .exclude(table__external_data_source__deleted=True)
+ .exclude(saved_query__deleted=True)
+ .select_related("certified_by")
+ )
+ for certification in certifications:
+ serialized = DatabaseSchemaTableCertification(
+ status=certification.status,
+ notes=certification.notes or None,
+ certified_by=certification.certified_by.email if certification.certified_by else None,
+ certified_at=certification.certified_at.isoformat() if certification.certified_at else None,
+ )
+ if certification.table_id is not None:
+ by_table_id[str(certification.table_id)] = serialized
+ elif certification.saved_query_id is not None:
+ by_saved_query_id[str(certification.saved_query_id)] = serialized
+ return by_table_id, by_saved_query_id
+ except Exception:
+ logger.exception("serialize_database: failed to load catalog certifications", team_id=team_id)
+ return {}, {}
+
+
def serialize_fields(
field_input,
context: HogQLContext,
diff --git a/posthog/hogql/database/test/__snapshots__/test_database.ambr b/posthog/hogql/database/test/__snapshots__/test_database.ambr
index 650734402857..29650fba144e 100644
--- a/posthog/hogql/database/test/__snapshots__/test_database.ambr
+++ b/posthog/hogql/database/test/__snapshots__/test_database.ambr
@@ -747,6 +747,7 @@
'''
{
"events": {
+ "certification": null,
"fields": {
"uuid": {
"chain": null,
@@ -1432,6 +1433,7 @@
"type": "posthog"
},
"groups": {
+ "certification": null,
"fields": {
"index": {
"chain": null,
@@ -1531,6 +1533,7 @@
"type": "posthog"
},
"persons": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -1664,6 +1667,7 @@
"type": "posthog"
},
"sessions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -2142,6 +2146,7 @@
"type": "posthog"
},
"logs": {
+ "certification": null,
"fields": {
"uuid": {
"chain": null,
@@ -2320,6 +2325,7 @@
"type": "posthog"
},
"query_log": {
+ "certification": null,
"fields": {
"event_date": {
"chain": null,
@@ -2608,6 +2614,7 @@
"type": "system"
},
"system.accounts": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -2801,6 +2808,7 @@
"type": "system"
},
"system.account_relationship_definitions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -2879,6 +2887,7 @@
"type": "system"
},
"system.account_relationships": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -2967,6 +2976,7 @@
"type": "system"
},
"system.activity_logs": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3035,6 +3045,7 @@
"type": "system"
},
"system.actions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3113,6 +3124,7 @@
"type": "system"
},
"system.alerts": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3271,6 +3283,7 @@
"type": "system"
},
"system.annotations": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3389,6 +3402,7 @@
"type": "system"
},
"system.batch_export_backfills": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3487,6 +3501,7 @@
"type": "system"
},
"system.batch_exports": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3635,6 +3650,7 @@
"type": "system"
},
"system.business_knowledge_chunks": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3723,6 +3739,7 @@
"type": "system"
},
"system.business_knowledge_documents": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3821,6 +3838,7 @@
"type": "system"
},
"system.business_knowledge_sources": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -3939,6 +3957,7 @@
"type": "system"
},
"system.cohort_calculation_history": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4007,6 +4026,7 @@
"type": "system"
},
"system.cohorts": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4135,6 +4155,7 @@
"type": "system"
},
"system.custom_property_definitions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4223,6 +4244,7 @@
"type": "system"
},
"system.dashboards": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4301,6 +4323,7 @@
"type": "system"
},
"system.dashboard_tiles": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4419,6 +4442,7 @@
"type": "system"
},
"system.data_modeling_jobs": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4527,6 +4551,7 @@
"type": "system"
},
"system.data_modeling_views": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4645,6 +4670,7 @@
"type": "system"
},
"system.data_modeling_endpoint_versions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4743,6 +4769,7 @@
"type": "system"
},
"system.data_modeling_endpoints": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4841,6 +4868,7 @@
"type": "system"
},
"system.data_warehouse_sources": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -4929,6 +4957,7 @@
"type": "system"
},
"system.data_warehouse_tables": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5027,6 +5056,7 @@
"type": "system"
},
"system.error_tracking_assignment_rules": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5125,6 +5155,7 @@
"type": "system"
},
"system.error_tracking_bypass_rules": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5203,6 +5234,7 @@
"type": "system"
},
"system.error_tracking_issue_assignments": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5251,6 +5283,7 @@
"type": "system"
},
"system.error_tracking_issue_fingerprints": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5299,6 +5332,7 @@
"type": "system"
},
"system.error_tracking_issues": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5357,6 +5391,7 @@
"type": "system"
},
"system.error_tracking_releases": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5425,6 +5460,7 @@
"type": "system"
},
"system.error_tracking_symbol_sets": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5493,6 +5529,7 @@
"type": "system"
},
"system.error_tracking_suppression_rules": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5581,6 +5618,7 @@
"type": "system"
},
"system.early_access_features": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5659,6 +5697,7 @@
"type": "system"
},
"system.experiments": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5777,6 +5816,7 @@
"type": "system"
},
"system.exports": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5825,6 +5865,7 @@
"type": "system"
},
"system.feature_flags": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -5903,6 +5944,7 @@
"type": "system"
},
"system.file_system": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -6021,6 +6063,7 @@
"type": "system"
},
"system.groups": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -6079,6 +6122,7 @@
"type": "system"
},
"system.group_type_mappings": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -6127,6 +6171,7 @@
"type": "system"
},
"system.information_schema.tables": {
+ "certification": null,
"fields": {
"table_catalog": {
"chain": null,
@@ -6195,6 +6240,7 @@
"type": "system"
},
"system.information_schema.columns": {
+ "certification": null,
"fields": {
"table_schema": {
"chain": null,
@@ -6323,6 +6369,7 @@
"type": "system"
},
"system.information_schema.relationships": {
+ "certification": null,
"fields": {
"source_table": {
"chain": null,
@@ -6391,6 +6438,7 @@
"type": "system"
},
"system.information_schema.data_types": {
+ "certification": null,
"fields": {
"type_name": {
"chain": null,
@@ -6419,6 +6467,7 @@
"type": "system"
},
"system.hog_flows": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -6537,6 +6586,7 @@
"type": "system"
},
"system.hog_functions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -6675,6 +6725,7 @@
"type": "system"
},
"system.ingestion_warnings": {
+ "certification": null,
"fields": {
"source": {
"chain": null,
@@ -6723,6 +6774,7 @@
"type": "system"
},
"system.integrations": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -6801,6 +6853,7 @@
"type": "system"
},
"system.integration_repository_cache": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -6959,6 +7012,7 @@
"type": "system"
},
"system.insight_variables": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7027,6 +7081,7 @@
"type": "system"
},
"system.logs_alerts": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7225,6 +7280,7 @@
"type": "system"
},
"system.logs_views": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7303,6 +7359,7 @@
"type": "system"
},
"system.insights": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7461,6 +7518,7 @@
"type": "system"
},
"system.notebooks": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7579,6 +7637,7 @@
"type": "system"
},
"system.sandbox_environments": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7697,6 +7756,7 @@
"type": "system"
},
"system.review_queue_items": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7785,6 +7845,7 @@
"type": "system"
},
"system.review_queues": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7863,6 +7924,7 @@
"type": "system"
},
"system.score_definitions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -7961,6 +8023,7 @@
"type": "system"
},
"system.session_recording_playlists": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -8099,6 +8162,7 @@
"type": "system"
},
"system.session_recordings": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -8297,6 +8361,7 @@
"type": "system"
},
"system.source_schemas": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -8435,6 +8500,7 @@
"type": "system"
},
"system.source_sync_jobs": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -8543,6 +8609,7 @@
"type": "system"
},
"system.support_tickets": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -8784,6 +8851,7 @@
"type": "system"
},
"system.surveys": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -8872,6 +8940,7 @@
"type": "system"
},
"system.task_runs": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -9000,6 +9069,7 @@
"type": "system"
},
"system.tags": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -9028,6 +9098,7 @@
"type": "system"
},
"system.tasks": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -9186,6 +9257,7 @@
"type": "system"
},
"system.teams": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -9254,6 +9326,7 @@
"type": "system"
},
"system.trace_review_scores": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -9382,6 +9455,7 @@
"type": "system"
},
"system.trace_reviews": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -9480,6 +9554,7 @@
"type": "system"
},
"system.usage_metrics": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -9584,6 +9659,7 @@
'''
{
"events": {
+ "certification": null,
"fields": {
"uuid": {
"chain": null,
@@ -10233,6 +10309,7 @@
"type": "posthog"
},
"groups": {
+ "certification": null,
"fields": {
"index": {
"chain": null,
@@ -10332,6 +10409,7 @@
"type": "posthog"
},
"persons": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -10465,6 +10543,7 @@
"type": "posthog"
},
"sessions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -10943,6 +11022,7 @@
"type": "posthog"
},
"logs": {
+ "certification": null,
"fields": {
"uuid": {
"chain": null,
@@ -11121,6 +11201,7 @@
"type": "posthog"
},
"query_log": {
+ "certification": null,
"fields": {
"event_date": {
"chain": null,
@@ -11409,6 +11490,7 @@
"type": "system"
},
"system.accounts": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -11602,6 +11684,7 @@
"type": "system"
},
"system.account_relationship_definitions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -11680,6 +11763,7 @@
"type": "system"
},
"system.account_relationships": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -11768,6 +11852,7 @@
"type": "system"
},
"system.activity_logs": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -11836,6 +11921,7 @@
"type": "system"
},
"system.actions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -11914,6 +12000,7 @@
"type": "system"
},
"system.alerts": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12072,6 +12159,7 @@
"type": "system"
},
"system.annotations": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12190,6 +12278,7 @@
"type": "system"
},
"system.batch_export_backfills": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12288,6 +12377,7 @@
"type": "system"
},
"system.batch_exports": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12436,6 +12526,7 @@
"type": "system"
},
"system.business_knowledge_chunks": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12524,6 +12615,7 @@
"type": "system"
},
"system.business_knowledge_documents": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12622,6 +12714,7 @@
"type": "system"
},
"system.business_knowledge_sources": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12740,6 +12833,7 @@
"type": "system"
},
"system.cohort_calculation_history": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12808,6 +12902,7 @@
"type": "system"
},
"system.cohorts": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -12936,6 +13031,7 @@
"type": "system"
},
"system.custom_property_definitions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13024,6 +13120,7 @@
"type": "system"
},
"system.dashboards": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13102,6 +13199,7 @@
"type": "system"
},
"system.dashboard_tiles": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13220,6 +13318,7 @@
"type": "system"
},
"system.data_modeling_jobs": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13328,6 +13427,7 @@
"type": "system"
},
"system.data_modeling_views": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13446,6 +13546,7 @@
"type": "system"
},
"system.data_modeling_endpoint_versions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13544,6 +13645,7 @@
"type": "system"
},
"system.data_modeling_endpoints": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13642,6 +13744,7 @@
"type": "system"
},
"system.data_warehouse_sources": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13730,6 +13833,7 @@
"type": "system"
},
"system.data_warehouse_tables": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13828,6 +13932,7 @@
"type": "system"
},
"system.error_tracking_assignment_rules": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -13926,6 +14031,7 @@
"type": "system"
},
"system.error_tracking_bypass_rules": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14004,6 +14110,7 @@
"type": "system"
},
"system.error_tracking_issue_assignments": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14052,6 +14159,7 @@
"type": "system"
},
"system.error_tracking_issue_fingerprints": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14100,6 +14208,7 @@
"type": "system"
},
"system.error_tracking_issues": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14158,6 +14267,7 @@
"type": "system"
},
"system.error_tracking_releases": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14226,6 +14336,7 @@
"type": "system"
},
"system.error_tracking_symbol_sets": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14294,6 +14405,7 @@
"type": "system"
},
"system.error_tracking_suppression_rules": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14382,6 +14494,7 @@
"type": "system"
},
"system.early_access_features": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14460,6 +14573,7 @@
"type": "system"
},
"system.experiments": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14578,6 +14692,7 @@
"type": "system"
},
"system.exports": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14626,6 +14741,7 @@
"type": "system"
},
"system.feature_flags": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14704,6 +14820,7 @@
"type": "system"
},
"system.file_system": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14822,6 +14939,7 @@
"type": "system"
},
"system.groups": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14880,6 +14998,7 @@
"type": "system"
},
"system.group_type_mappings": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -14928,6 +15047,7 @@
"type": "system"
},
"system.information_schema.tables": {
+ "certification": null,
"fields": {
"table_catalog": {
"chain": null,
@@ -14996,6 +15116,7 @@
"type": "system"
},
"system.information_schema.columns": {
+ "certification": null,
"fields": {
"table_schema": {
"chain": null,
@@ -15124,6 +15245,7 @@
"type": "system"
},
"system.information_schema.relationships": {
+ "certification": null,
"fields": {
"source_table": {
"chain": null,
@@ -15192,6 +15314,7 @@
"type": "system"
},
"system.information_schema.data_types": {
+ "certification": null,
"fields": {
"type_name": {
"chain": null,
@@ -15220,6 +15343,7 @@
"type": "system"
},
"system.hog_flows": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -15338,6 +15462,7 @@
"type": "system"
},
"system.hog_functions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -15476,6 +15601,7 @@
"type": "system"
},
"system.ingestion_warnings": {
+ "certification": null,
"fields": {
"source": {
"chain": null,
@@ -15524,6 +15650,7 @@
"type": "system"
},
"system.integrations": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -15602,6 +15729,7 @@
"type": "system"
},
"system.integration_repository_cache": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -15760,6 +15888,7 @@
"type": "system"
},
"system.insight_variables": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -15828,6 +15957,7 @@
"type": "system"
},
"system.logs_alerts": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16026,6 +16156,7 @@
"type": "system"
},
"system.logs_views": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16104,6 +16235,7 @@
"type": "system"
},
"system.insights": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16262,6 +16394,7 @@
"type": "system"
},
"system.notebooks": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16380,6 +16513,7 @@
"type": "system"
},
"system.sandbox_environments": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16498,6 +16632,7 @@
"type": "system"
},
"system.review_queue_items": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16586,6 +16721,7 @@
"type": "system"
},
"system.review_queues": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16664,6 +16800,7 @@
"type": "system"
},
"system.score_definitions": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16762,6 +16899,7 @@
"type": "system"
},
"system.session_recording_playlists": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -16900,6 +17038,7 @@
"type": "system"
},
"system.session_recordings": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -17098,6 +17237,7 @@
"type": "system"
},
"system.source_schemas": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -17236,6 +17376,7 @@
"type": "system"
},
"system.source_sync_jobs": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -17344,6 +17485,7 @@
"type": "system"
},
"system.support_tickets": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -17585,6 +17727,7 @@
"type": "system"
},
"system.surveys": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -17673,6 +17816,7 @@
"type": "system"
},
"system.task_runs": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -17801,6 +17945,7 @@
"type": "system"
},
"system.tags": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -17829,6 +17974,7 @@
"type": "system"
},
"system.tasks": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -17987,6 +18133,7 @@
"type": "system"
},
"system.teams": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -18055,6 +18202,7 @@
"type": "system"
},
"system.trace_review_scores": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -18183,6 +18331,7 @@
"type": "system"
},
"system.trace_reviews": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
@@ -18281,6 +18430,7 @@
"type": "system"
},
"system.usage_metrics": {
+ "certification": null,
"fields": {
"id": {
"chain": null,
diff --git a/posthog/schema.py b/posthog/schema.py
index f257382c2bc3..cbda9a18ec4c 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -67,6 +67,7 @@ from posthog.schema_enums import (
CustomChannelField as CustomChannelField,
CustomChannelOperator as CustomChannelOperator,
DatabaseSchemaManagedViewTableKind as DatabaseSchemaManagedViewTableKind,
+ DatabaseSchemaTableCertificationStatus as DatabaseSchemaTableCertificationStatus,
DatabaseSchemaTableType as DatabaseSchemaTableType,
DatabaseSerializedFieldType as DatabaseSerializedFieldType,
DataColorToken as DataColorToken,
@@ -4397,32 +4398,27 @@ class DatabaseSchemaField(BaseModel):
type: DatabaseSerializedFieldType
-class DatabaseSchemaPostHogTable(BaseModel):
+class DatabaseSchemaTableCertification(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
- fields: dict[str, DatabaseSchemaField]
- id: str
- name: str
- row_count: float | None = None
- type: Literal["posthog"] = "posthog"
-
-
-class DatabaseSchemaSystemTable(BaseModel):
- model_config = ConfigDict(
- extra="forbid",
+ certified_at: str | None = None
+ certified_by: str | None = None
+ notes: str | None = None
+ status: DatabaseSchemaTableCertificationStatus = Field(
+ ...,
+ description=("Settled data catalog trust mark: 'certified' (prefer this source) or 'deprecated' (avoid it)."),
)
- fields: dict[str, DatabaseSchemaField]
- id: str
- name: str
- row_count: float | None = None
- type: Literal["system"] = "system"
class DatabaseSchemaTableCommon(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
fields: dict[str, DatabaseSchemaField]
id: str
name: str
@@ -14731,6 +14727,10 @@ class DatabaseSchemaBatchExportTable(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
fields: dict[str, DatabaseSchemaField]
id: str
name: str
@@ -14742,6 +14742,10 @@ class DatabaseSchemaDataWarehouseTable(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
fields: dict[str, DatabaseSchemaField]
format: str | None = Field(
default=None,
@@ -14765,6 +14769,36 @@ class DatabaseSchemaDataWarehouseTable(BaseModel):
)
+class DatabaseSchemaPostHogTable(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
+ fields: dict[str, DatabaseSchemaField]
+ id: str
+ name: str
+ row_count: float | None = None
+ type: Literal["posthog"] = "posthog"
+
+
+class DatabaseSchemaSystemTable(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
+ fields: dict[str, DatabaseSchemaField]
+ id: str
+ name: str
+ row_count: float | None = None
+ type: Literal["system"] = "system"
+
+
class DocumentSimilarityQueryResponse(BaseModel):
model_config = ConfigDict(
extra="forbid",
@@ -24427,6 +24461,10 @@ class DatabaseSchemaEndpointTable(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
fields: dict[str, DatabaseSchemaField]
id: str
name: str
@@ -24440,6 +24478,10 @@ class DatabaseSchemaManagedViewTable(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
fields: dict[str, DatabaseSchemaField]
id: str
kind: DatabaseSchemaManagedViewTableKind
@@ -24454,6 +24496,10 @@ class DatabaseSchemaMaterializedViewTable(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
fields: dict[str, DatabaseSchemaField]
id: str
last_run_at: str | None = None
@@ -24468,6 +24514,10 @@ class DatabaseSchemaViewTable(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ certification: DatabaseSchemaTableCertification | None = Field(
+ default=None,
+ description=("Present only when the table or view carries a settled data catalog certification."),
+ )
fields: dict[str, DatabaseSchemaField]
id: str
name: str
diff --git a/posthog/schema_enums.py b/posthog/schema_enums.py
index 2de7695f756d..477491c3a7f5 100644
--- a/posthog/schema_enums.py
+++ b/posthog/schema_enums.py
@@ -853,6 +853,11 @@ class DatabaseSchemaManagedViewTableKind(StrEnum):
REVENUE_ANALYTICS_SUBSCRIPTION = "revenue_analytics_subscription"
+class DatabaseSchemaTableCertificationStatus(StrEnum):
+ CERTIFIED = "certified"
+ DEPRECATED = "deprecated"
+
+
class DatabaseSchemaTableType(StrEnum):
POSTHOG = "posthog"
SYSTEM = "system"
diff --git a/products/data_catalog/backend/tests/test_certifications.py b/products/data_catalog/backend/tests/test_certifications.py
index ff6a3f5f5632..9c5f5a3440d7 100644
--- a/products/data_catalog/backend/tests/test_certifications.py
+++ b/products/data_catalog/backend/tests/test_certifications.py
@@ -10,6 +10,9 @@ from parameterized import parameterized
from rest_framework import status
from rest_framework.exceptions import ValidationError
+from posthog.hogql.context import HogQLContext
+from posthog.hogql.database.database import Database
+
from posthog.models.personal_api_key import PersonalAPIKey
from posthog.models.team import Team
from posthog.models.utils import generate_random_token_personal, hash_key_value
@@ -29,7 +32,11 @@ from products.data_catalog.backend.presentation.serializers import (
CertificationSerializer,
)
from products.data_modeling.backend.facade.models import DataWarehouseSavedQuery
-from products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSource
+from products.warehouse_sources.backend.facade.models import (
+ DataWarehouseCredential,
+ DataWarehouseTable,
+ ExternalDataSource,
+)
def _table(
@@ -339,3 +346,68 @@ class TestCertificationInputValidation(SimpleTestCase):
serializer = CertificationCreateSerializer(data={field: "not-a-uuid"})
assert not serializer.is_valid()
assert field in serializer.errors
+
+
+class TestSerializedSchemaCertification(APIBaseTest):
+ def setUp(self) -> None:
+ super().setUp()
+ flag_patch = patch("products.data_catalog.backend.facade.flags.is_data_catalog_enabled", return_value=True)
+ flag_patch.start()
+ self.addCleanup(flag_patch.stop)
+ credential = DataWarehouseCredential.objects.create(access_key="key", access_secret="secret", team=self.team)
+ self.warehouse_table = DataWarehouseTable.objects.create(
+ name="stripe_customers",
+ format="Parquet",
+ team=self.team,
+ credential=credential,
+ url_pattern="https://bucket.s3/data/*",
+ columns={"id": {"hogql": "StringDatabaseField", "clickhouse": "Nullable(String)", "schema_valid": True}},
+ )
+ self.view = DataWarehouseSavedQuery.objects.create(
+ team=self.team,
+ name="revenue_view",
+ query={"kind": "HogQLQuery", "query": "select event from events limit 1"},
+ columns={"event": "String"},
+ )
+
+ def _serialized_tables(self) -> dict:
+ database = Database.create_for(team=self.team, user=self.user)
+ context = HogQLContext(team=self.team, team_id=self.team.pk, database=database)
+ return database.serialize(context)
+
+ @parameterized.expand(
+ [("table", "stripe_customers", certify, "certified"), ("view", "revenue_view", deprecate, "deprecated")]
+ )
+ def test_settled_certification_serialized_on_schema(
+ self, target_type: str, table_key: str, action, expected_status: str
+ ) -> None:
+ target_selector: dict[str, Any] = (
+ {"table_id": str(self.warehouse_table.id)}
+ if target_type == "table"
+ else {"saved_query_id": str(self.view.id)}
+ )
+ action(
+ propose_certification(team=self.team, user=self.user, notes="canonical source", **target_selector),
+ self.user,
+ )
+
+ certification = self._serialized_tables()[table_key].certification
+
+ assert certification is not None
+ assert certification.status == expected_status
+ assert certification.notes == "canonical source"
+ assert certification.certified_by == self.user.email
+
+ def test_proposed_certification_absent_from_schema(self) -> None:
+ propose_certification(team=self.team, user=self.user, table_id=str(self.warehouse_table.id))
+
+ tables = self._serialized_tables()
+
+ assert tables["stripe_customers"].certification is None
+ assert tables["revenue_view"].certification is None
+
+ def test_certification_absent_when_flag_off(self) -> None:
+ certify(propose_certification(team=self.team, user=self.user, table_id=str(self.warehouse_table.id)), self.user)
+
+ with patch("products.data_catalog.backend.facade.flags.is_data_catalog_enabled", return_value=False):
+ assert self._serialized_tables()["stripe_customers"].certification is None
diff --git a/products/data_catalog/frontend/certificationsLogic.test.ts b/products/data_catalog/frontend/certificationsLogic.test.ts
index ff69fa08e0d7..580c882a2ff2 100644
--- a/products/data_catalog/frontend/certificationsLogic.test.ts
+++ b/products/data_catalog/frontend/certificationsLogic.test.ts
@@ -1,3 +1,5 @@
+import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
+
import { initKeaTests } from '~/test/init'
import { expectLogic } from '~/test/keaTestUtils'
@@ -43,6 +45,9 @@ jest.mock('./generated/api', () => ({
dataCatalogCertificationsDestroy: jest.fn(),
}))
+// The whole logic module is mocked above; loadDatabase is a jest.fn at runtime.
+const mockLoadDatabase = (databaseTableListLogic as unknown as { loadDatabase: jest.Mock }).loadDatabase
+
function buildCertification(overrides: Partial<DataCatalogCertificationApi>): DataCatalogCertificationApi {
return {
id: 'cert-1',
@@ -86,6 +91,8 @@ describe('certificationsLogic', () => {
expect(logic.values.certifications.find((certification) => certification.id === 'cert-1')?.status).toEqual(
'certified'
)
+ // Badges elsewhere read certification state off the shared schema, so it must be refreshed.
+ expect(mockLoadDatabase).toHaveBeenCalledWith({ force: true })
})
it('removes the row when revoking', async () => {
@@ -95,5 +102,7 @@ describe('certificationsLogic', () => {
await expectLogic(logic).toFinishAllListeners()
expect(logic.values.certifications.map((certification) => certification.id)).not.toContain('cert-1')
+ // Badges elsewhere read certification state off the shared schema, so it must be refreshed.
+ expect(mockLoadDatabase).toHaveBeenCalledWith({ force: true })
})
})
diff --git a/products/data_catalog/frontend/certificationsLogic.tsx b/products/data_catalog/frontend/certificationsLogic.tsx
index 9933698ff8e0..53b06e983d6d 100644
--- a/products/data_catalog/frontend/certificationsLogic.tsx
+++ b/products/data_catalog/frontend/certificationsLogic.tsx
@@ -199,6 +199,8 @@ export const certificationsLogic = kea<certificationsLogicType>([
actions.loadCertificationsSuccess(
values.certifications.map((certification) => (certification.id === id ? updated : certification))
)
+ // Badges elsewhere read certification state off the shared schema, so refresh it.
+ actions.loadDatabase({ force: true })
} catch (error) {
lemonToast.error(apiErrorDetail(error) || failureMessage)
} finally {
@@ -252,6 +254,8 @@ export const certificationsLogic = kea<certificationsLogicType>([
actions.loadCertificationsSuccess(
values.certifications.filter((certification) => certification.id !== id)
)
+ // Badges elsewhere read certification state off the shared schema, so refresh it.
+ actions.loadDatabase({ force: true })
lemonToast.success('Certification revoked')
} catch (error) {
lemonToast.error(apiErrorDetail(error) || 'Could not revoke the certification. Try again.')
diff --git a/products/data_catalog/manifest.tsx b/products/data_catalog/manifest.tsx
index 5d419347045f..3c27fd8e809e 100644
--- a/products/data_catalog/manifest.tsx
+++ b/products/data_catalog/manifest.tsx
@@ -40,6 +40,7 @@ export const manifest: ProductManifest = {
iconType: 'data_warehouse',
href: urls.dataCatalog(),
flag: FEATURE_FLAGS.PRODUCT_DATA_CATALOG,
+ tags: ['alpha'],
sceneKey: 'DataCatalog',
},
],
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 2e46b73cbe51..727af513418f 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -16950,7 +16950,25 @@ export namespace Schemas {
export type DatabaseSchemaBatchExportTableFields = {[key: string]: DatabaseSchemaField};
+ export type DatabaseSchemaTableCertificationStatus = typeof DatabaseSchemaTableCertificationStatus[keyof typeof DatabaseSchemaTableCertificationStatus];
+
+
+ export const DatabaseSchemaTableCertificationStatus = {
+ Certified: 'certified',
+ Deprecated: 'deprecated',
+ } as const;
+
+ export interface DatabaseSchemaTableCertification {
+ certified_at?: string | null;
+ certified_by?: string | null;
+ notes?: string | null;
+ /** Settled data catalog trust mark: 'certified' (prefer this source) or 'deprecated' (avoid it). */
+ status: DatabaseSchemaTableCertificationStatus;
+ }
+
export interface DatabaseSchemaBatchExportTable {
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification | null;
fields: DatabaseSchemaBatchExportTableFields;
id: string;
name: string;
@@ -16979,6 +16997,8 @@ export namespace Schemas {
}
export interface DatabaseSchemaDataWarehouseTable {
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification | null;
fields: DatabaseSchemaDataWarehouseTableFields;
/** Absent for a dual-mode source's virtual tables, which have no synced S3 backing. */
format?: string | null;
@@ -16997,6 +17017,8 @@ export namespace Schemas {
export type DatabaseSchemaEndpointTableFields = {[key: string]: DatabaseSchemaField};
export interface DatabaseSchemaEndpointTable {
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification | null;
fields: DatabaseSchemaEndpointTableFields;
id: string;
name: string;
@@ -17021,6 +17043,8 @@ export namespace Schemas {
} as const;
export interface DatabaseSchemaManagedViewTable {
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification | null;
fields: DatabaseSchemaManagedViewTableFields;
id: string;
kind: DatabaseSchemaManagedViewTableKind;
@@ -17034,6 +17058,8 @@ export namespace Schemas {
export type DatabaseSchemaMaterializedViewTableFields = {[key: string]: DatabaseSchemaField};
export interface DatabaseSchemaMaterializedViewTable {
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification | null;
fields: DatabaseSchemaMaterializedViewTableFields;
id: string;
last_run_at?: string | null;
@@ -17047,6 +17073,8 @@ export namespace Schemas {
export type DatabaseSchemaPostHogTableFields = {[key: string]: DatabaseSchemaField};
export interface DatabaseSchemaPostHogTable {
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification | null;
fields: DatabaseSchemaPostHogTableFields;
id: string;
name: string;
@@ -17057,6 +17085,8 @@ export namespace Schemas {
export type DatabaseSchemaSystemTableFields = {[key: string]: DatabaseSchemaField};
export interface DatabaseSchemaSystemTable {
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification | null;
fields: DatabaseSchemaSystemTableFields;
id: string;
name: string;
@@ -17067,6 +17097,8 @@ export namespace Schemas {
export type DatabaseSchemaViewTableFields = {[key: string]: DatabaseSchemaField};
export interface DatabaseSchemaViewTable {
+ /** Present only when the table or view carries a settled data catalog certification. */
+ certification?: DatabaseSchemaTableCertification | null;
fields: DatabaseSchemaViewTableFields;
id: string;
name: string;