: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
fix(data-warehouse): scope schema-collapsible UI to postgres warehouse sources (#59267)
Daniel RC3bf268e1225f
diff --git a/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx b/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsxindex 8ceaea192edf..213971a43efe 100644--- a/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/SchemaForm.tsx@@ -53,6 +53,7 @@ export default function SchemaForm(): JSX.Element {const containerRef = useFloatingContainer()const {toggleSchemaShouldSync,+ toggleAllTables,openSyncMethodModal,toggleDirectQuerySchemaGroup,setExpandedDirectQuerySchemaKeys,@@ -66,10 +67,13 @@ export default function SchemaForm(): JSX.Element {schemaNameFilter,suggestedTablesMap,isDirectQueryMode,+ selectedConnector,+ tablesAllToggledOn,source,groupedDirectQueryDatabaseSchema,expandedDirectQuerySchemaKeys,} = useValues(sourceWizardLogic)+ const isPostgresWarehouseMode = !isDirectQueryMode && selectedConnector?.name === 'Postgres'const onClickCheckbox = (schema: ExternalDataSourceSyncSchema, checked: boolean): void => {if (!isDirectQueryMode && schema.sync_type === null) {@@ -89,6 +93,240 @@ export default function SchemaForm(): JSX.Element {const showRows = databaseSchema.some((schema) => schema.rows != null)const hasManySchemas = databaseSchema.length > 10+ const warehouseColumns = [+ {+ width: 0,+ key: 'enabled',+ render: function RenderEnabled(_: unknown, schema: ExternalDataSourceSyncSchema) {+ return (+ <LemonCheckbox+ checked={schema.should_sync}+ onChange={(checked) => onClickCheckbox(schema, checked)}+ />+ )+ },+ },+ {+ title: 'Table',+ key: 'table',+ render: function RenderTable(_: unknown, schema: ExternalDataSourceSyncSchema) {+ const isSuggested = suggestedTablesMap[schema.table] !== undefined+ const tooltip =+ suggestedTablesMap[schema.table] ?? 'This table is suggested to be enabled for this source'++ return (+ <div className="flex items-center gap-2">+ <span+ className="font-mono cursor-pointer"+ onClick={() => onClickCheckbox(schema, !schema.should_sync)}+ >+ {schema.label || schema.table}+ </span>+ {schema.description && (+ <Tooltip title={schema.description}>+ <IconInfo className="text-muted-alt text-base" />+ </Tooltip>+ )}+ {isSuggested && (+ <Tooltip title={tooltip} placement="top">+ <LemonTag type="primary" className="cursor-help">+ Suggested+ </LemonTag>+ </Tooltip>+ )}+ </div>+ )+ },+ },+ {+ title: 'Rows',+ key: 'rows',+ isHidden: !databaseSchema.some((schema) => schema.rows),+ render: function RenderRows(_: unknown, schema: ExternalDataSourceSyncSchema) {+ if (schema.rows != null) {+ return schema.rows+ }+ return (+ <Tooltip title="Row count was skipped for this table because counting would require a full scan (e.g. plain views, Memory/Buffer/Log-engine tables, or Kafka/URL table functions). The table can still be synced — we just don't know its size up front.">+ <span className="text-muted-alt cursor-help">Skipped</span>+ </Tooltip>+ )+ },+ },+ {+ key: 'sync_field',+ title: 'Sync field',+ align: 'right' as const,+ tooltip:+ 'Incremental and append-only refresh methods key on a unique field to determine the most up-to-date data.',+ isHidden: !shouldShowSyncColumns || !databaseSchema.some((schema) => schema.sync_type),+ render: function RenderSyncType(_: unknown, schema: ExternalDataSourceSyncSchema) {+ if (isDirectQueryMode) {+ return (+ <span className="text-xs text-muted-foreground">+ Only selected tables are queryable in direct mode+ </span>+ )+ }+ if (!schema.incremental_available && !schema.append_available) {+ return <span className="text-xs text-muted-foreground">Incremental sync not supported</span>+ }++ if (schema.sync_type === 'webhook') {+ return <LemonTag type="success">Webhook</LemonTag>+ }++ if (schema.sync_type !== 'full_refresh' && schema.sync_type !== null && schema.incremental_field) {+ const field = schema.incremental_fields.find((f) => f.field == schema.incremental_field) ?? null++ if (field) {+ return (+ <div className="flex items-center justify-end">+ {field.nullable && (+ <Tooltip+ title={`This field is nullable. Any rows where ${field.label} is null will not be synced.`}+ >+ <IconWarning className="mr-1 text-warning text-xl" />+ </Tooltip>+ )}+ <span className="leading-5">{field.label}</span>+ <LemonTag className="ml-2" type="success">+ {field.type}+ </LemonTag>+ </div>+ )+ }+ }++ return <span className="text-xs text-muted-foreground">No sync field selected</span>+ },+ },+ {+ key: 'primary_key',+ title: 'Primary key',+ align: 'right' as const,+ tooltip:+ 'The column(s) used to uniquely identify rows for deduplication during incremental syncs. Auto-detected if not set.',+ isHidden: !shouldShowSyncColumns || !databaseSchema.some((schema) => schema.sync_type === 'incremental'),+ render: function RenderPrimaryKey(_: unknown, schema: ExternalDataSourceSyncSchema) {+ if (schema.sync_type !== 'incremental') {+ return <span className="text-xs text-muted-foreground">No primary key selected</span>+ }++ if (!schema.primary_key_columns || schema.primary_key_columns.length === 0) {+ const detected = schema.detected_primary_keys+ if (detected && detected.length > 0) {+ return (+ <div className="flex items-center justify-end gap-1 flex-wrap">+ {detected.map((col) => (+ <LemonTag key={col} type="muted">+ {col}+ </LemonTag>+ ))}+ </div>+ )+ }++ return <span className="text-xs text-muted-foreground">None detected</span>+ }++ return (+ <div className="flex items-center justify-end gap-1 flex-wrap">+ {schema.primary_key_columns.map((col) => (+ <LemonTag key={col} type="default">+ {col}+ </LemonTag>+ ))}+ </div>+ )+ },+ },+ {+ key: 'sync_type',+ title: 'Sync method',+ align: 'right' as const,+ isHidden: !shouldShowSyncColumns,+ tooltip:+ 'Full refresh will refresh the full table on every sync, whereas incremental will only sync new and updated rows since the last sync',+ render: function RenderSyncType(_: unknown, schema: ExternalDataSourceSyncSchema) {+ if (isDirectQueryMode) {+ return (+ <span className="text-xs text-muted-foreground">+ Only selected tables are queryable in direct mode+ </span>+ )+ }+ if (!schema.sync_type) {+ return (+ <div className="justify-end flex">+ <LemonButton+ className="my-1"+ type="primary"+ onClick={() => openSyncMethodModal(schema)}+ size="small"+ >+ Configure+ </LemonButton>+ </div>+ )+ }+ return (+ <div className="justify-end flex">+ <LemonButton+ className="my-1"+ size="small"+ type="secondary"+ onClick={() => openSyncMethodModal(schema)}+ disabledReason={+ !schema.incremental_available && !schema.append_available && !schema.supports_webhooks+ ? 'Full refresh is the only supported sync method for this table'+ : undefined+ }+ >+ {SyncTypeLabelMap[schema.sync_type]}+ </LemonButton>+ </div>+ )+ },+ },+ {+ key: 'columns',+ title: 'Columns',+ align: 'right' as const,+ isHidden: !shouldShowSyncColumns,+ tooltip:+ 'Pick a subset of columns to sync. Primary keys and the active incremental field are always retained.',+ render: function RenderColumns(_: unknown, schema: ExternalDataSourceSyncSchema) {+ if (schema.available_columns.length === 0) {+ return <span className="text-xs text-muted-foreground">—</span>+ }+ const synced = schema.enabled_columns+ const alwaysRetained = new Set<string>([+ ...(schema.primary_key_columns ?? []),+ ...(schema.incremental_field ? [schema.incremental_field] : []),+ ])+ const syncedCount = synced+ ? new Set([...synced, ...alwaysRetained]).size+ : schema.available_columns.length+ const summary = !synced+ ? `All ${schema.available_columns.length}`+ : `${syncedCount} of ${schema.available_columns.length}`+ return (+ <div className="justify-end flex">+ <LemonButton+ className="my-1"+ size="small"+ type="secondary"+ onClick={() => setColumnSelectionSchema(schema)}+ >+ {summary}+ </LemonButton>+ </div>+ )+ },+ },+ ]+return (<><div className="flex flex-col gap-2 flex-1 min-h-0">@@ -119,7 +357,11 @@ export default function SchemaForm(): JSX.Element {<LemonCollapsemultipleembedded- activeKeys={expandedDirectQuerySchemaKeys}+ activeKeys={+ groupedDirectQueryDatabaseSchema.length === 1+ ? groupedDirectQueryDatabaseSchema.map((g) => g.schemaName)+ : expandedDirectQuerySchemaKeys+ }onChange={setExpandedDirectQuerySchemaKeys}panels={groupedDirectQueryDatabaseSchema.map(({ schemaName, tables }) => {const selectedTablesCount = tables.filter((table) => table.should_sync).length@@ -226,347 +468,90 @@ export default function SchemaForm(): JSX.Element {) : (<div className="border rounded px-4 py-8 text-center text-muted-alt">No tables found</div>)- ) : groupedDirectQueryDatabaseSchema.length > 0 ? (- <div className="border rounded bg-bg-light">- <LemonCollapse- multiple- embedded- activeKeys={expandedDirectQuerySchemaKeys}- onChange={setExpandedDirectQuerySchemaKeys}- panels={groupedDirectQueryDatabaseSchema.map(- ({- schemaName,- tables,- }: {- schemaName: string- tables: ExternalDataSourceSyncSchema[]- }) => ({- key: schemaName,- header: (- <div className="flex items-center justify-between gap-3 w-full">- <div className="flex items-center gap-2 min-w-0">- <LemonCheckbox- checked={getSchemaSelectionState(tables)}- stopPropagation- onChange={(checked) =>- toggleDirectQuerySchemaGroup(schemaName, checked)- }- />- <span className="font-semibold truncate">{schemaName}</span>- </div>- <span className="text-xs text-muted-alt whitespace-nowrap">- {tables.filter((t) => t.should_sync).length} of {tables.length}{' '}- tables- </span>- </div>- ),- content: (- <LemonTable- embedded- showHeader={false}- dataSource={tables}- pagination={{ pageSize: 100, hideOnSinglePage: true }}- columns={[- {- width: 0,- key: 'enabled',- render: function RenderEnabled(_, schema) {- return (- <LemonCheckbox- checked={schema.should_sync}- onChange={(checked) =>- onClickCheckbox(schema, checked)- }- />- )- },- },- {- title: 'Table',- key: 'table',- render: function RenderTable(_, schema) {- const isSuggested =- suggestedTablesMap[schema.table] !== undefined- const tooltip =- suggestedTablesMap[schema.table] ??- 'This table is suggested to be enabled for this source'-- return (- <div className="flex items-center gap-2">- <span- className="font-mono cursor-pointer"- onClick={() =>- onClickCheckbox(schema, !schema.should_sync)- }- >- {schema.label || schema.table}- </span>- {schema.description && (- <Tooltip title={schema.description}>- <IconInfo className="text-muted-alt text-base" />- </Tooltip>- )}- {isSuggested && (- <Tooltip title={tooltip} placement="top">- <LemonTag- type="primary"- className="cursor-help"- >- Suggested- </LemonTag>- </Tooltip>- )}- </div>- )- },- },- {- title: 'Rows',- key: 'rows',- isHidden: !databaseSchema.some((schema) => schema.rows),- render: function RenderRows(_, schema) {- if (schema.rows != null) {- return schema.rows- }- return (- <Tooltip title="Row count was skipped for this table because counting would require a full scan (e.g. plain views, Memory/Buffer/Log-engine tables, or Kafka/URL table functions). The table can still be synced — we just don't know its size up front.">- <span className="text-muted-alt cursor-help">- Skipped- </span>- </Tooltip>- )- },- },- {- key: 'sync_field',- title: 'Sync field',- align: 'right',- tooltip:- 'Incremental and append-only refresh methods key on a unique field to determine the most up-to-date data.',- isHidden:- !shouldShowSyncColumns ||- !databaseSchema.some((schema) => schema.sync_type),- render: function RenderSyncType(_, schema) {- if (isDirectQueryMode) {- return (- <span className="text-xs text-muted-foreground">- Only selected tables are queryable in direct- mode- </span>- )- }- if (- !schema.incremental_available &&- !schema.append_available- ) {- return (- <span className="text-xs text-muted-foreground">- Incremental sync not supported- </span>- )- }-- if (schema.sync_type === 'webhook') {- return <LemonTag type="success">Webhook</LemonTag>- }-- if (- schema.sync_type !== 'full_refresh' &&- schema.sync_type !== null &&- schema.incremental_field- ) {- const field =- schema.incremental_fields.find(- (f) => f.field == schema.incremental_field- ) ?? null-- if (field) {- return (- <div className="flex items-center justify-end">- {field.nullable && (- <Tooltip- title={`This field is nullable. Any rows where ${field.label} is null will not be synced.`}- >- <IconWarning className="mr-1 text-warning text-xl" />- </Tooltip>- )}- <span className="leading-5">- {field.label}- </span>- <LemonTag className="ml-2" type="success">- {field.type}- </LemonTag>- </div>- )- }- }-- return (- <span className="text-xs text-muted-foreground">- No sync field selected- </span>- )- },- },- {- key: 'primary_key',- title: 'Primary key',- align: 'right',- tooltip:- 'The column(s) used to uniquely identify rows for deduplication during incremental syncs. Auto-detected if not set.',- isHidden:- !shouldShowSyncColumns ||- !databaseSchema.some(- (schema) => schema.sync_type === 'incremental'- ),- render: function RenderPrimaryKey(_, schema) {- if (schema.sync_type !== 'incremental') {- return (- <span className="text-xs text-muted-foreground">- No primary key selected- </span>- )- }-- if (- !schema.primary_key_columns ||- schema.primary_key_columns.length === 0- ) {- const detected = schema.detected_primary_keys- if (detected && detected.length > 0) {- return (- <div className="flex items-center justify-end gap-1 flex-wrap">- {detected.map((col) => (- <LemonTag key={col} type="muted">- {col}- </LemonTag>- ))}- </div>- )- }-- return (- <span className="text-xs text-muted-foreground">- None detected- </span>- )- }-- return (- <div className="flex items-center justify-end gap-1 flex-wrap">- {schema.primary_key_columns.map((col) => (- <LemonTag key={col} type="default">- {col}- </LemonTag>- ))}- </div>- )- },- },- {- key: 'sync_type',- title: 'Sync method',- align: 'right',- isHidden: !shouldShowSyncColumns,- tooltip:- 'Full refresh will refresh the full table on every sync, whereas incremental will only sync new and updated rows since the last sync',- render: function RenderSyncType(_, schema) {- if (isDirectQueryMode) {- return (- <span className="text-xs text-muted-foreground">- Only selected tables are queryable in direct- mode- </span>- )- }- if (!schema.sync_type) {- return (- <div className="justify-end flex">- <LemonButton- className="my-1"- type="primary"- onClick={() => openSyncMethodModal(schema)}- size="small"- >- Configure- </LemonButton>- </div>- )- }- return (- <div className="justify-end flex">- <LemonButton- className="my-1"- size="small"- type="secondary"- onClick={() => openSyncMethodModal(schema)}- disabledReason={- !schema.incremental_available &&- !schema.append_available &&- !schema.supports_webhooks- ? 'Full refresh is the only supported sync method for this table'- : undefined- }- >- {SyncTypeLabelMap[schema.sync_type]}- </LemonButton>- </div>- )- },- },- {- key: 'columns',- title: 'Columns',- align: 'right',- isHidden: !shouldShowSyncColumns,- tooltip:- 'Pick a subset of columns to sync. Primary keys and the active incremental field are always retained.',- render: function RenderColumns(_, schema) {- if (schema.available_columns.length === 0) {- return (- <span className="text-xs text-muted-foreground">- —- </span>- )+ ) : isPostgresWarehouseMode ? (+ groupedDirectQueryDatabaseSchema.length > 0 ? (+ <div className="border rounded bg-bg-light">+ <LemonCollapse+ multiple+ embedded+ activeKeys={+ groupedDirectQueryDatabaseSchema.length === 1+ ? groupedDirectQueryDatabaseSchema.map((g) => g.schemaName)+ : expandedDirectQuerySchemaKeys+ }+ onChange={setExpandedDirectQuerySchemaKeys}+ panels={groupedDirectQueryDatabaseSchema.map(+ ({+ schemaName,+ tables,+ }: {+ schemaName: string+ tables: ExternalDataSourceSyncSchema[]+ }) => ({+ key: schemaName,+ header: (+ <div className="flex items-center justify-between gap-3 w-full">+ <div className="flex items-center gap-2 min-w-0">+ <LemonCheckbox+ checked={getSchemaSelectionState(tables)}+ stopPropagation+ onChange={(checked) =>+ toggleDirectQuerySchemaGroup(schemaName, checked)}- const synced = schema.enabled_columns- const alwaysRetained = new Set<string>([- ...(schema.primary_key_columns ?? []),- ...(schema.incremental_field- ? [schema.incremental_field]- : []),- ])- const syncedCount = synced- ? new Set([...synced, ...alwaysRetained]).size- : schema.available_columns.length- const summary = !synced- ? `All ${schema.available_columns.length}`- : `${syncedCount} of ${schema.available_columns.length}`- return (- <div className="justify-end flex">- <LemonButton- className="my-1"- size="small"- type="secondary"- onClick={() => setColumnSelectionSchema(schema)}- >- {summary}- </LemonButton>- </div>- )- },- },- ]}- />- ),- })- )}- />- </div>+ />+ <span className="font-semibold truncate">{schemaName}</span>+ </div>+ <span className="text-xs text-muted-alt whitespace-nowrap">+ {tables.filter((t) => t.should_sync).length} of {tables.length}{' '}+ tables+ </span>+ </div>+ ),+ content: (+ <LemonTable+ embedded+ showHeader={false}+ dataSource={tables}+ pagination={{ pageSize: 100, hideOnSinglePage: true }}+ columns={warehouseColumns}+ />+ ),+ })+ )}+ />+ </div>+ ) : (+ <div className="border rounded px-4 py-8 text-center text-muted-alt">+ {schemaNameFilter ? `No tables match "${schemaNameFilter}"` : 'No schemas found'}+ </div>+ )) : (- <div className="border rounded px-4 py-8 text-center text-muted-alt">- {schemaNameFilter ? `No tables match "${schemaNameFilter}"` : 'No schemas found'}- </div>+ <LemonTable+ emptyState={schemaNameFilter ? `No tables match "${schemaNameFilter}"` : 'No schemas found'}+ dataSource={filteredDatabaseSchema}+ pagination={{ pageSize: 100, hideOnSinglePage: true }}+ columns={[+ {+ ...warehouseColumns[0],+ title: (+ <LemonCheckbox+ checked={tablesAllToggledOn}+ onChange={(checked) =>+ toggleAllTables(+ checked,+ schemaNameFilter+ ? filteredDatabaseSchema.map(+ (s: ExternalDataSourceSyncSchema) => s.table+ )+ : undefined+ )+ }+ />+ ),+ },+ ...warehouseColumns.slice(1),+ ]}+ />)}</div></div>