Introducing a new way to review your PRs.

Read the announcement

frappe / insights

Open Source Business Intelligence Tool

View on GitHub

25 documents · Updated Nov 23, 2026

docs / data-sources-and-store

Data sources and data store

Insights gives queries one view of data from external systems and from a managed local store. A data source describes where analytical data comes from. A table record connects a source table to Insights, while the data store holds selected copies for faster and more stable query runs.

Data source model

Source connection

An Insights Data Source is the named connection between Insights and an analytical system. It records the source kind, connection details, and whether the connection is active. Database sources use a supported database engine, while REST API sources use an API base URL and a selected authentication method. The site database is a protected special source that Insights needs for its own data.

The source validates the fields that apply to its kind and tests access when a normal source is saved. A successful test marks the source active and allows Insights to refresh its table list. A source connection is reused during work, then closed at the end of the request, so queries and table discovery use one source identity without keeping connections open. Local DuckDB connections use the private site area and open in read-only mode unless a controlled store write is in progress.

References: insights/…/insights_data_source_v3.py• L43-121 insights/…/insights_data_source_v3.py• L274-357 insights/…/insights_data_source_v3.py• L407-466 insights/…/insights_data_source_v3.py• L556-575

Source table registry

An Insights Table is the local record for one table exposed by a data source. It gives the table a user-facing label and links it to its source. This record is the stable object that the query builder uses when it offers tables and columns to a user.

Refreshing a source discovers its available tables and updates this registry. Table names remain tied to their source, so the same name in two sources does not represent the same query input. For a PostgreSQL source that spans several schemas, the registry keeps the remote table identity stable when its displayed name gains or loses a schema prefix. This prevents one remote table from becoming two local records. The registry carries sync state for tables that have a stored copy.

References: insights/…/insights_data_source_v3.py• L359-425 insights/…/insights_data_source_v3.py• L468-524 insights/…/insights_data_source_v3.py• L526-545 insights/…/insights_table_v3.json• L26-72

Source metadata

Insights exposes source metadata as query input rather than as raw connection details. The source list reports identity, type, status, and special database markers. Table browsing can return a table preview, row count, column list, or a complete schema with Insights data types.

This metadata path reads the source directly for exploration. It applies the same table and user restrictions that a query uses, so a preview does not become a way to bypass access rules. See Data source management for the source setup and metadata APIs.

References: insights/…/data_sources.py• L19-35 insights/…/data_sources.py• L69-113 insights/…/data_sources.py• L190-219 insights/…/insights_table_v3.py• L135-155

Managed data store

Stored table copy

The data store is one Insights-managed DuckDB database that keeps selected source tables inside the site. A table becomes part of the data store when an administrator imports it. The table record remains the source of truth for its source and table name, while the stored flag and sync time show whether a local copy is available and when it was last refreshed.

The store uses a separate namespace for each source. This keeps stored tables from different sources distinct even when their source table names match. The store is private site data and is separate from the source system. Local DuckDB sources can also be opened through the same controlled connection boundary, but they remain source data rather than managed store data.

References: insights/…/data_warehouse.py• L34-112 insights/…/data_warehouse.py• L327-365 insights/…/data_warehouse.py• L851-854 insights/…/insights_data_source_v3.py• L304-330 insights/…/insights_table_v3.py• L29-41 insights/…/insights_table_v3.py• L157-174

Store synchronization

Importing a table is an asynchronous sync from the source to the data store. A full sync replaces the stored copy. An incremental sync starts from a time-like cursor and can append new rows or update existing rows by a stable key. The sync records progress and import status, then updates the table record only after a successful write, so the store reflects completed data rather than an intended run.

The import writes source data in batches and commits the completed result as one store update. A later incremental run takes its bookmark from the committed store data. This prevents a partial run from advancing the point at which the next run starts. Imports can add columns that appeared in the source, and the system prevents duplicate imports for the same table while one is in progress. Store writes wait for active readers and serialize other writers, so a refresh does not replace a file while a query still uses it.

A query that needs a missing stored table queues an import and can use an empty table with the expected shape while the import runs. The query must be refreshed after the import completes. REST API sources remain available for live exploration but are rejected by this table-store import path. See Data-store administration for import actions and sync settings.

References: insights/…/data_warehouse.py• L144-252 insights/…/data_warehouse.py• L260-305 insights/…/data_warehouse.py• L345-421 insights/…/data_warehouse.py• L430-505 insights/…/data_warehouse.py• L527-703 insights/…/data_warehouse.py• L720-803 insights/…/duckdb.py• L78-168 insights/…/data_store.py• L52-70

Store administration

The data store is enabled through the single Insights Settings record. Its table list shows only stored tables and includes the source, database type, and last sync time. Administrators can request an import for a source table or refresh the stored tables used by a query.

The store also has cleanup and migration support. Cleanup uses stored table records, import-job records, and query use to distinguish active data from abandoned data. It can un-store unused full-sync tables and remove only warehouse tables that can be rebuilt or are safe to drop. Incremental tables are not pruned automatically because the source history needed to rebuild them may no longer exist. Unexplained tables that may hold the only copy are kept and reported. The store can also rebuild its database file when dropped space is large enough to make compaction useful. See Data-store administration for settings, store actions, and maintenance rules.

References: insights/…/insights_settings.json• L130-145 insights/…/data_store.py• L7-49 insights/…/insights_query_v3.py• L364-384 insights/…/data_warehouse.py• L856-882 insights/…/data_warehouse.py• L885-1001 insights/…/data_warehouse.py• L1004-1057 insights/…/data_warehouse.py• L1060-1132 insights/…/data_warehouse.py• L1164-1231

Query data access

Query source selection

A query starts from a registered table or from another query. The selected table carries its data source, which gives the query both its source identity and its available schema. Query operations preserve this source relationship when the query is built from a saved query.

The query path can use a live source connection or the managed store. Live access is needed for source exploration and for REST API data. Stored access is the normal path for imported database tables. If a stored table is missing, the query path requests an import and reads a temporary empty table with the right shape until the store is ready. Native SQL follows the same table binding path when it uses the store, so source table names resolve to the stored namespace and source SQL is translated for the store before execution. Native queries use one statement and do not support schema-qualified table names in this path.

This diagram shows how a configured source becomes queryable through its table record and then reaches either a live connection or the managed store.

flowchart LR
    A[Configured data source] --> B[Registered source tables]
    B --> C[Query source selection]
    C --> D{Access mode}
    D -->|Live| E[External source connection]
    D -->|Stored| F[Managed data store]
    E --> G[Query result]
    F --> G

References: frontend/…/query.ts• L133-149 insights/…/insights_table_v3.py• L135-155 insights/…/data_warehouse.py• L345-365 insights/…/ibis_utils.py• L293-310 insights/…/ibis_utils.py• L861-969 insights/…/ibis_utils.py• L971-1049

Query expression boundary

A query expression is a user-authored formula that transforms columns or builds a query value. It can use the approved query functions and data types, but it cannot open files, use URLs, connect to a backend, or write query output outside the query result. The same boundary applies when Insights validates an expression for the editor and when it evaluates the expression during a query.

Expressions can read values from JSON columns as typed query values. A path can reach nested object keys or list positions. A missing key, invalid JSON, or JSON null becomes an empty value, while a source placeholder such as an empty string can be treated as empty before filtering or grouping. This keeps source-specific data cleanup inside the query without giving the expression access to another data source.

References: insights/…/functions.py• L572-736 insights/…/functions.py• L1079-1117 insights/…/ibis_utils.py• L1207-1221 insights/…/ibis_utils.py• L1386-1418 insights/…/test_json_functions.py• L40-114 insights/…/utils.py• L14-52 insights/…/utils.py• L55-130

Query access control

Source and table access are linked. When team permissions are off, the permission query allows all sources and tables in this area. When they are on, a source is available when the user can access its tables or the source itself through the team rules.

The same checks apply before a table is exposed to a query or preview. This keeps source browsing, stored-table browsing, and query execution within the same access boundary. See Data exploration for the user-facing table and preview flow.

References: insights/permissions.py• L125-183 insights/…/data_sources.py• L69-77 insights/…/data_sources.py• L116-137 insights/…/data_store.py• L18-24

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the data source fields, client source types, and source creation payload aligned when a new source kind or connection mode is added.
  • Keep source table discovery, PostgreSQL table identity, and table renaming aligned. A mismatch can create a second record for one remote table.
  • Keep source table discovery and table naming aligned with the stored-table namespace. A mismatch can make a table visible but prevent its stored copy from being found.
  • Keep the stored flag, sync timestamps, sync bookmarks, and import-log status aligned with the actual data-store commit. Queries and cleanup use these records as the store contract.
  • Keep live-source permission checks and stored-table permission queries aligned. A preview must not show rows that the same query cannot read.
  • Keep REST API sources out of database-table import paths unless the store gains a supported API import flow.
  • Keep cleanup's rebuild checks aligned with the sync mode. A full-sync table can be rebuilt, but an incremental table may depend on source history that is no longer available.
  • Keep the expression allow-list free of file, URL, backend, and output access when query functions or the expression validator changes.
  • Keep JSON value parsing, type names, and null handling aligned between live sources and DuckDB store queries.
  • Keep source SQL rules and DuckDB translation aligned. Native SQL must remain a single supported statement and must resolve through registered table bindings in store mode.
  • Keep local DuckDB reads and store writes inside the shared lock boundary. A write that bypasses it can conflict with cached readers or another writer.

Important failure modes

TriggerConsequenceGuard
Required connection or API fields are missingThe source cannot be saved or testedSource validation checks fields by source kind before connection use
A source connection test failsThe source is marked inactive and table discovery does not provide usable metadataTest the connection again after correcting the source configuration
A stored table import failsThe local copy is not refreshed, and the import is marked failedInspect the import status and retry after the source or sync settings are fixed
A query requests a stored table that is not presentInsights queues an import and may return an empty result with the correct schema until the import finishesWait for the import to finish, then refresh the query
A REST API table is sent through the store import pathThe import is rejected because this path supports database sources onlyUse live API access or a supported import-job flow
An incremental table loses its bookmark or required cursor and keyThe next sync can fail or repeat the wrong part of the source historyKeep the cursor, key, sync start, and committed bookmark together
A source table gains columns while an incremental import runsThe stored copy can reject or misplace incoming data if its schema is not extendedPreserve name-based column handling when store writers change
A native query uses unsupported syntax, multiple statements, or schema-qualified table names in store modeThe query is rejected or cannot be translated to DuckDBUse one supported statement with registered table names and SQL supported by both dialects
A native query uses a stored procedure through the data storeStore execution rejects the queryUse live access for supported stored procedures
An expression reads malformed JSON or requests an unsupported JSON typeThe value is empty for malformed input, or expression validation rejects the typeUse supported JSON types and handle empty values in the query
An expression tries to read or write through an Ibis I/O attribute or escape the expression sandboxExpression validation or execution is rejectedUse only the approved query functions and expression namespace
A table or source is outside the caller's permission scopeThe table is not returned or the query is deniedApply the same source and table permission checks to new access paths
Cleanup cannot prove that a warehouse table is replaceableThe table stays in place and is reported instead of being droppedKeep the table record or import job that owns the data aligned with the warehouse table

Key files

FileWhy to read it
insights/…/insights_data_source_v3.pyDefines the source lifecycle, validation, connection access, table identity, and table discovery contract.
insights/…/insights_data_source_v3.jsonDefines the source fields and the connection choices presented to administrators.
insights/…/insights_table_v3.pyConnects a source table to live or stored query access and starts store imports.
insights/…/insights_table_v3.jsonDefines table identity, stored state, and sync settings.
insights/…/data_sources.pyExposes source lists, table metadata, previews, and table-link refresh actions.
insights/…/data_store.pyExposes stored-table listing, import requests, and scheduled store sync.
insights/…/data_warehouse.pyDefines the managed store, source-table import boundary, committed sync state, and cleanup rules.
insights/…/duckdb.pyDefines the controlled read and write boundary for local and remote DuckDB access.
insights/…/ibis_utils.pyShows how queries choose live or stored access, bind native SQL to registered tables, and execute results.
insights/…/functions.pyDefines query helpers for typed JSON values and source placeholder cleanup.
insights/…/test_json_functions.pyShows the supported JSON shapes, typed values, missing-value behavior, and placeholder cleanup that queries rely on.
insights/…/utils.pyDefines the expression namespace and blocks expression access to files, URLs, and backends.
frontend/…/data_source.tsShows how the client loads sources, tests connections, and creates source records.
frontend/…/data_store.tsShows how the client lists stored tables and requests imports.
frontend/…/query.tsShows how a query derives its source from its operations.