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-store-administration

Data store administration

The Insights data store is a managed local copy of selected source tables. It gives queries a faster path for repeated reads and lets one query combine data from different source systems. Administration covers the feature switch, import requests, stored-table discovery, resource state in the client, scheduled refresh, and safe cleanup. See Data sources and data store for the wider source model, Data source management for source and table metadata, and Deployment, setup, and migrations for installation changes.

Administration model

The data store separates a source table from its managed copy. An Insights Table v3 record describes the source table and its stored state; a stored record means that the managed copy is available for query use. Imports run as background work, so an administrator requests an import and later checks the sync time rather than waiting for the table copy in the browser. References: insights/…/insights_table_v3.py• L20-41, insights/…/insights_table_v3.py• L157-174, insights/…/data_warehouse.py• L749-765

The feature is controlled by the single Insights Settings document. Its data-store controls enable the feature and set the maximum rows and memory used during imports. The client starts with the same operational defaults and saves these values through the normal settings resource. References: insights/…/insights_settings.json• L8-18, insights/…/insights_settings.json• L112-140, frontend/…/settings.ts• L11-29, frontend/…/DataStoreSettings.vue• L10-42

Administrator workflow

The administration flow moves from enabling the feature to selecting source tables and then tracking their availability. The browser exposes the data-store view only after the feature is enabled, and only administrators can start an import.

This diagram shows how an administrator request becomes a stored table and how later scheduled work keeps the copy current.

flowchart LR
    A[Enable data store] --> B[Open Data Store]
    B --> C[Choose data source]
    C --> D[Choose source table]
    D --> E[Request import]
    E --> F[Background warehouse import]
    F --> G[Stored table and sync time]
    G --> H[Daily refresh]
    H --> F

Feature access

The Data Store setting is part of the organization settings dialog. When enable_data_store is false, the main navigation hides the Data Store link; when it is true, the /data-store route opens the stored-table list. The route still uses the normal signed-in application guard. References: frontend/…/Settings.vue• L19-47, frontend/…/DataStoreSettings.vue• L10-19, frontend/…/AppSidebar.vue• L69-99, frontend/…/router.ts• L85-89, frontend/…/router.ts• L123-143

Table import

The import dialog first loads tables for a selected data source. It shows the source row count so the administrator can choose an import limit, then sends the source and table identity to the data-store resource. The server checks the Insights Admin role and queues the warehouse import. References: frontend/…/ImportTableDialog.vue• L13-55, frontend/…/tables.ts• L17-30, frontend/…/tables.ts• L69-73, frontend/…/data_store.ts• L46-61, insights/…/data_store.py• L51-56, insights/…/insights_table_v3.py• L157-162

The data-store endpoints also declare the types of their request arguments at the public API boundary. Frappe checks and coerces these arguments before list or import work starts, so malformed values do not reach the database or table lookup as unchecked input. References: insights/…/data_store.py• L7-8, insights/…/data_store.py• L51-55

The import limits control the amount of source data and memory used by the managed store. The settings page supplies the site-wide row and memory limits, while the import dialog shows a row-count choice for the selected table. References: frontend/…/DataStoreSettings.vue• L21-33, frontend/…/ImportTableDialog.vue• L13-17, insights/…/insights_settings.json• L112-140

Stored-table review

The Data Store page lists only tables marked as stored. Each row links the table to its data source and database type and shows the last successful sync time in a human-readable form. The page filters the loaded table names as the administrator searches, while the API also supports server-side search for other clients. References: frontend/…/DataStoreList.vue• L11-31, frontend/…/DataStoreList.vue• L33-70, frontend/…/data_store.ts• L7-44, insights/…/data_store.py• L7-48

The data-store API scopes its table list through the caller's permission query conditions. This keeps the administration view aligned with the table access rules instead of treating the managed store as a separate permission boundary. Import remains an administrator action even when a user can view stored-table metadata. References: insights/…/data_store.py• L17-24, insights/…/data_store.py• L51-56, frontend/…/DataStoreList.vue• L56-68, frontend/…/DataStoreList.vue• L73-101

Resource handling

The frontend uses a shared data-store resource to keep table lists and import state reactive across the list page and import dialog. It caches results in memory by data source, reports loading state, converts sync timestamps to relative time, and refreshes the selected source list after an import request completes. Errors are shown through the common error-toast path. References: frontend/…/data_store.ts• L1-71

Settings use a document resource instead of browser storage. The resource loads the single Insights Settings document, tracks dirty state, saves only changed settings, and shows a success notice after the server accepts the update. This prevents local browser state from making the site-wide data-store switch appear enabled on one client only. References: frontend/…/settings.ts• L5-39, frontend/…/DataStoreSettings.vue• L35-42, frontend/…/resource.ts• L35-63, frontend/…/resource.ts• L84-121, frontend/…/resource.ts• L186-219

Refresh and cleanup

The scheduler keeps the managed store current without a browser session. A daily task imports every table still marked as stored. An hourly task changes imports that remain in progress for more than one hour to failed, which prevents stale work from looking active forever. A weekly task removes unused or orphaned warehouse data and compacts the store when this can reduce its size. References: insights/hooks.py• L164-180, insights/…/data_store.py• L58-85, insights/…/data_warehouse.py• L773-799

Cleanup uses query use and sync state to decide what can be removed. It does not prune a recently imported table, a table used by a recent query, or an incremental table whose missing history cannot be rebuilt safely. It also keeps unexplained warehouse tables that still contain rows and reports them for review. References: insights/…/data_warehouse.py• L802-817, insights/…/data_warehouse.py• L921-974, insights/…/test_data_store_cleanup.py• L124-190, insights/…/test_data_store_cleanup.py• L250-298

Migration support

Migration support preserves the link between source-table records and their managed copies as the warehouse layout evolves. The schema migration moves legacy flat warehouse tables into a separate schema for each data source. It skips sites without a warehouse file or stored tables and logs missing or failed moves for follow-up. References: insights/…/migrate_warehouse_tables_to_schemas.py• L4-12, insights/…/migrate_warehouse_tables_to_schemas.py• L22-60

The upgrade sequence enables the data store when an installation already has stored tables, then performs the warehouse schema migration in the ordered post-model patch list. This lets older sites retain an active data-store experience while their warehouse names change. References: insights/…/enable_data_store.py• L4-6, insights/patches.txt• L5-16

PostgreSQL sources with one configured schema no longer need that schema prefix in their table names. The cleanup patch removes the redundant prefix from stored table records and uses the shared rename path so dependent queries, references, table links, import history, permissions, and managed copies keep the same table identity. If an imported copy cannot be renamed, the record is marked for re-import instead of pointing to missing data. References: insights/…/strip_default_schema_from_table_names.py• L6-43, insights/…/table_rename.py• L44-65, insights/…/table_rename.py• L83-125, insights/…/table_rename.py• L280-314

Change checklist

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

  • Keep the enable_data_store setting, the sidebar visibility rule, and the /data-store route aligned. A mismatch can make an enabled feature unreachable or expose a view without its intended entry point.
  • Keep the stored-table API fields aligned with DataStoreTable and the list columns. Changes to table identity or sync-time fields can silently break search or status display.
  • Keep endpoint type annotations aligned with the values accepted by clients. Frappe now performs the boundary check and coercion for these data-store APIs.
  • Keep import authorization aligned across the API and InsightsTablev3.import_to_warehouse. Both layers must preserve the administrator boundary.
  • Keep the stored flag and warehouse table naming rules aligned with daily refresh and weekly cleanup. Cleanup uses those records to decide which physical tables are live or safe to remove.
  • When changing warehouse or source-table names, update query operations, query references, table links, import logs, permissions, and any migration that maps old names to new names.

Important failure modes

TriggerConsequenceGuard
The feature switch is falseThe Data Store link is hidden and users cannot reach the administration viewEnable Insights Settings.enable_data_store before directing users to the data-store route
A client sends a value with the wrong typeThe endpoint rejects or converts the value before list or import work runsKeep the API annotations and client request values aligned; Frappe checks the endpoint arguments
A non-admin submits an import requestThe import is rejected before warehouse work startsThe API and table document both require the Insights Admin role
A warehouse import stays in progress for over one hourThe import record can remain misleadingly activeThe hourly task marks stale in-progress records as failed
A stored table is unused beyond the retention windowIts managed copy is un-stored and can be removedRecent imports and recent query use are protected; incremental tables are never pruned
A warehouse table has rows but no matching explanationCleanup leaves it in place and records an error instead of deleting possible source dataReview the cleanup report and repair the table or its ownership record
A table rename changes only the warehouse nameQueries, import history, permissions, or links can point to the old table identityThe shared rename path updates table records and all known dependent references

Key files

FileWhy to read it
insights/…/data_store.pyDefines the stored-table listing, typed API boundary, administrator import request, daily refresh, and stale-status handling.
frontend/…/data_store.tsShows the shared client resource for stored-table data, loading state, and import refresh.
frontend/…/DataStoreList.vueShows the user-facing review page and its administrator-only import entry point.
frontend/…/ImportTableDialog.vueShows how an administrator selects a source table and sets an import row limit.
frontend/…/DataStoreSettings.vueShows the site controls for enabling the store and limiting import size and memory.
insights/…/insights_table_v3.pyDefines the source-table state and the administrator boundary for warehouse actions.
insights/…/data_warehouse.pyExplains background imports, warehouse state, cleanup, orphan protection, and compaction.
insights/hooks.pyShows when refresh, failure recovery, and cleanup run.
insights/patches.txtShows the order of data-store-related upgrade patches.
insights/…/migrate_warehouse_tables_to_schemas.pyShows the legacy warehouse layout migration.
insights/…/strip_default_schema_from_table_names.pyShows how redundant PostgreSQL schema prefixes are removed from single-schema sources.
insights/…/table_rename.pyShows how a table-name change preserves dependent references, permissions, import history, and the managed copy.