Deployment, setup, and migrations
Insights runs as a Frappe app with a site database and a separate analytical store for imported table data. Deployment creates the Frappe site and its service links. Setup can add a ready-to-use demo data source and workbook. Site migration keeps stored data, table identity, column metadata, query links, access records, invitation links, dashboard layouts, workbook copies, and export settings usable as the data model changes.
Deployment environment
The development deployment uses Docker Compose to provide MariaDB, Redis, and a Frappe bench. The bench container creates or reuses a Frappe installation, connects it to the other containers, installs Insights, and serves the site on the published web port (docker/docker-compose.yml• L2-31, docker/init.sh• L3-40).
MariaDB stores the Frappe site records. Redis supports the bench services. Insights uses its own analytical data store for data that users import or keep for analysis. This split lets site metadata and analytical table data follow separate lifecycles; see Data store administration.
The startup path is:
- Compose starts MariaDB and Redis with persistent MariaDB storage.
- The Frappe container runs the initialization script.
- The script creates a version 15 bench when one does not exist.
- The bench points its database and queue services at the container names.
- The script downloads the Insights app and creates
insights.localhost. - The site installs Insights, enables the settings needed by the development setup, and starts the bench.
This path is intended for local development. Production deployment uses the normal Frappe deployment process. The app hook still supplies install and migrate actions such as the Admin team and workbook template sync (README.md• L62-113, insights/hooks.py• L92-106). The broader request and service lifecycle is described in Application runtime.
Application setup
Application setup prepares the site records and services that make Insights available after installation. The install and migrate hooks call the same post-migrate work. They ensure an Admin team exists with the Administrator as a member, then check for newer shipped workbook templates (insights/hooks.py• L92-99, insights/migrate.py• L8-30).
The app exposes Insights at /insights by default. A site can set insights_path when another page already uses that route. This changes the URL route without changing the stored workbook or data-source model (insights/hooks.py• L15-27, insights/hooks.py• L238-243).
Demo provisioning
The demo setup creates a small, complete analysis environment for an Insights Admin. It registers a DuckDB data source named demo_data, places the demo database in the site’s private files, discovers its tables, creates the table relationships used by the sample analysis, and imports the Order Analysis workbook (insights/…/setup_wizard.py• L10-33, insights/…/demo.py• L40-55).
The setup is safe to repeat. If the data source exposes at least eight tables and has at least eight table links, the factory treats the demo as ready and does not download or rebuild it. An admin-only check can report that state before setup. The setup reports progress to the current user so the UI can show download and table-sync status (insights/…/demo.py• L27-37, insights/…/demo.py• L87-94).
The demo flow is:
flowchart TD
A[Admin checks or starts demo setup] --> B[Register demo_data source]
B --> C{Demo tables and links ready?}
C -->|Yes| D[Return ready]
C -->|No| E{Test or CI run?}
E -->|Yes| F[Generate DuckDB data from the demo spec]
E -->|No| G[Download production DuckDB data]
F --> H[Sync table list]
G --> H
H --> I[Create eight table links]
I --> J[Import Order Analysis workbook]
Normal installation downloads the demo database from its remote source. Tests and continuous integration generate the database in place from the declarative demo specification instead, so they do not depend on a committed binary or a network download. A failed production download is logged and returned to the admin as a setup error. The setup also skips its data side effects in test and CI contexts except for the generated local database (insights/…/demo.py• L19-24, insights/…/demo.py• L57-65, insights/…/demo.py• L96-111, insights/…/setup_wizard.py• L25-33).
Fixtures and workbook imports
The demo data fixture provides the source tables for the sample workbook. Its declarative specification defines the table shape, generated values, links between tables, and time relationships. The generator writes a DuckDB file and checks that every table has rows and every declared foreign key has matching parent rows before it replaces the target file (insights/…/spec.py• L4-9, insights/…/generator.py• L41-64, insights/…/generator.py• L78-113).
The generated data models an order-analysis domain with customers, sellers, products, orders, payments, reviews, and locations. A fixed seed gives stable row values for tests, while the integrity check protects the joins used by the sample workbook. The command-line entry point can generate the file and print the integrity report without a Frappe site (insights/…/spec.py• L196-338, insights/…/generator.py• L306-330).
The sample workbook fixture is a portable definition of one workbook and its dependent queries, charts, and dashboard. Its query uses the demo source. Its dashboard presents order metrics and order status views, with the multi-reading number chart represented as one dashboard item per reading (insights/…/sample_workbook.json• L1-25, insights/…/sample_workbook.json• L221-324, insights/…/sample_workbook.json• L407-513).
Workbook import creates a new workbook, then restores its dependent objects while remapping old fixture IDs to new site IDs. This preserves links between queries, charts, dashboard items, and dashboard filters when the same fixture is imported into different sites (insights/…/insights_workbook.py• L68-177, insights/…/insights_workbook.py• L480-493). For the workbook model and its use in analysis, see Workbooks.
Apps can also ship workbook templates through the insights_workbooks hook. Insights discovers templates from installed apps, filters them by required apps, and records the source template and imported version on the site workbook. A newer template updates a pristine imported copy during migration. A copy with local edits is left in place and is offered for deliberate update instead (insights/hooks.py• L30-36, insights/…/templates.py• L64-73, insights/…/templates.py• L173-218, insights/…/templates.py• L407-437).
Migration sequence
Frappe runs the entries in insights/patches.txt in two phases. Pre-model-sync patches run before the current DocType definitions are synchronized. Post-model-sync patches run after that sync. The order is part of the upgrade contract because later patches expect the records or fields prepared by earlier patches (insights/patches.txt• L1-54).
Pre-model synchronization
The pre-model phase protects old installations before the current schema replaces their model. It blocks an unsafe v2 upgrade, changes workbook names to the string type used by link fields, and moves legacy workbook data into the current records (insights/patches.txt• L1-4, insights/…/check_legacy_v2_data_before_upgrade.py• L14-55, insights/…/name_workbooks_as_strings.py• L9-23).
The v2 check blocks an upgrade when a dashboard used in the last 30 days has not been migrated. It identifies recent use through v2 query execution records and treats a dashboard as migrated when a current dashboard stores its former name. An explicit site setting can bypass the block when the old work is not needed. Queries outside dashboards do not block the upgrade because the legacy migrator moves dashboards only. Workbook naming preserves the sequence so existing names remain stable and new workbooks continue after them.
References: insights/patches.txt• L1-4 insights/…/check_legacy_v2_data_before_upgrade.py• L14-118 insights/…/name_workbooks_as_strings.py• L9-73
Data model and analytical store migration
The first post-model changes bring data sources, stored tables, schemas, table links, query references, and saved columns into the current data model. They also enable data storage and download behavior for existing sites (insights/patches.txt• L6-18, insights/…/backfill_table_columns.py• L11-29).
Table-column backfill is queued as a long job because it must read each source table. Migration can finish while a source is offline, but column search remains incomplete for tables that the job cannot read until a later sync or retry.
References: insights/patches.txt• L6-18 insights/…/backfill_table_columns.py• L11-49
Visibility and permission migration
The next group makes visibility and execution identity explicit. Public flags on current charts and dashboards move to the widest Public visibility level before the old is_public field is retired. Organization-wide shares then become visibility levels. Public charts run with a stable owner context. Existing alerts receive a permission user, while retired site-wide and content-level permission fields are removed (insights/patches.txt• L19-20, insights/patches.txt• L32-39, insights/…/set_visibility_from_is_public.py• L3-20, insights/…/set_visibility_from_org_shares.py• L6-32, insights/…/run_public_charts_as_owner.py• L15-35, insights/…/backfill_permission_user.py• L4-16).
The same transition reports where site-table access, table restrictions, backend attribute names, or trusted script names can change query results or stop a run. These patches create upgrade items instead of silently changing cases that need an owner or administrator to review (insights/…/report_site_data_follows_desk.py• L1-16, insights/…/rewrite_backend_attribute_names.py• L21-31, insights/…/report_upgrade_items.py• L38-48).
References: insights/…/set_visibility_from_is_public.py• L3-20 insights/…/set_visibility_from_org_shares.py• L6-32 insights/…/run_public_charts_as_owner.py• L15-55 insights/…/report_site_data_follows_desk.py• L1-16 insights/…/rewrite_backend_attribute_names.py• L21-31
Workbook and chart data migration
The workbook data group repairs stored query and visualization state so current readers produce the same intended results. It fixes Sankey value aggregation, retires unused chart query caches, normalizes number-card comparisons and chart settings, removes date defaults that were never applied, and converts dashboard cells to the current grid (insights/patches.txt• L21-31).
Number-card comparisons are normalized before cell sizing. Cell resizing then converts the old grid unit, number cards are split into one cell per reading, compact gaps are restored, and the final chart pass writes the common chart shape and stable reading IDs (insights/…/normalize_number_card_comparisons.py• L8-32, insights/…/resize_dashboard_cells.py• L26-41, insights/…/split_number_cells.py• L19-27, insights/…/close_dashboard_layout_gaps.py• L4-23, insights/…/normalize_chart_configs.py• L18-29).
Cross-workbook query sources are copied into the workbook that uses them. Folder titles are made unique within a workbook and table restrictions lose an old underscore form. These changes keep query ownership, dashboard filter links, and saved expressions valid under the current workbook rules (insights/…/copy_cross_workbook_query_sources.py• L13-30, insights/…/number_duplicate_folder_titles.py• L8-15, insights/…/drop_underscore_from_table_restrictions.py• L8-15).
References: insights/…/normalize_number_card_comparisons.py• L8-33 insights/…/resize_dashboard_cells.py• L26-125 insights/…/split_number_cells.py• L19-50 insights/…/close_dashboard_layout_gaps.py• L4-23 insights/…/normalize_chart_configs.py• L18-53 insights/…/copy_cross_workbook_query_sources.py• L13-95 insights/…/drop_unapplied_date_range_defaults.py• L8-29
Sharing, alerts, and upgrade review
The final data-model group moves access from individual workbook members to workbook shares. It preserves the access that can be represented at workbook level, reports shares that cannot be preserved, then moves alert execution to a user who can still edit the alert's workbook and see the intended rows (insights/patches.txt• L42-48, insights/…/share_workbooks_with_member_owners.py• L15-31, insights/…/reshape_member_shares.py• L16-25, insights/…/move_alert_run_as.py• L12-21).
Upgrade reporting runs after these ownership changes. It records items for lost edit access, public content that cannot run as its owner, trusted code, refused script names, replaced workbook templates, and changed fiscal-year behavior. Orphaned secret values are deleted after their query variables are gone (insights/…/report_upgrade_items.py• L38-48, insights/…/delete_orphaned_variable_secrets.py• L4-15).
References: insights/…/share_workbooks_with_member_owners.py• L15-39 insights/…/reshape_member_shares.py• L16-85 insights/…/move_alert_run_as.py• L12-64 insights/…/report_upgrade_items.py• L38-237 insights/…/delete_orphaned_variable_secrets.py• L4-15
Operational defaults and preview cleanup
The last patches add defaults for export size and data-store limits, mark upgrade state, and remove or detach old dashboard preview files. Preview cleanup is a privacy boundary because a rendered preview can contain rows selected by the user who generated it (insights/patches.txt• L49-54, insights/…/set_data_store_limits.py• L4-11, insights/…/clear_standard_dashboard_previews.py• L4-25, insights/…/detach_dashboard_previews.py• L8-18).
References: insights/…/set_max_export_rows.py• L4-7 insights/…/set_data_store_limits.py• L4-11 insights/…/mark_v3_users.py• L1-6 insights/…/clear_standard_dashboard_previews.py• L4-25 insights/…/detach_dashboard_previews.py• L8-48
Migration safety boundaries
Patches are selective when a site does not use the affected feature. The legacy-v2 check returns when there are no recent unmigrated dashboards or when the explicit site override is set. It also handles sites where legacy tables or current dashboard tables do not yet exist. Model conversion patches return when their tables or legacy fields do not exist. Chart and dashboard patches skip records without readable matching configurations. Settings patches preserve stored values (insights/…/check_legacy_v2_data_before_upgrade.py• L14-23, insights/…/check_legacy_v2_data_before_upgrade.py• L91-110, insights/…/name_workbooks_as_strings.py• L24-29, insights/…/normalize_number_card_comparisons.py• L24-33, insights/…/normalize_chart_configs.py• L30-53, insights/…/set_data_store_limits.py• L5-11).
Most data rewrites are safe to repeat because they select only old or missing values. Dashboard row conversion is the exception: a saved cell does not identify its old grid unit. Its patch-log guard prevents a second conversion. The patch order also prevents a current reader from seeing a partially migrated number-card or query model (insights/…/resize_dashboard_cells.py• L26-40, insights/…/resize_dashboard_cells.py• L59-77, insights/patches.txt• L23-31).
Some repairs need source data or dependency checks. Column backfill needs a live source. Cache retirement keeps queries used by another query, chart, or alert. Cross-workbook copying reports missing variable values and cycles as upgrade items rather than copying secrets or creating an invalid dependency (insights/…/backfill_table_columns.py• L31-49, insights/…/retire_chart_query_cache.py• L81-133, insights/…/copy_cross_workbook_query_sources.py• L148-211).
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the Docker service names, bench host settings, and site creation arguments aligned. A change in one can leave the bench running while unable to reach MariaDB or Redis.
- Keep the demo table names and join columns aligned with both the generated demo specification and sample_workbook.json. The workbook can import successfully while returning empty or incorrect results if the source contract changes.
- Keep the generated fixture's seed, table order, and integrity rules aligned with the workbook's expected data shape. A valid file can still change the sample's useful result ranges when its distributions change.
- Keep the migration order aligned with the model state each patch expects. Pre-model-sync code must not depend on fields that exist only after model sync.
- When changing legacy-v2 detection, preserve the link from recent query execution to the v2 dashboard and the
old_namemarker used to prove migration. Keep the explicit site override limited to sites that accept loss of unmigrated v2 data. - When changing table identity, schema rules, or saved column metadata, update stored table records, analytical table names, query operations, query references, table links, column search inputs, and resource permissions as one contract.
- When changing workbook naming, preserve both the database type expected by workbook link fields and the counter used for new workbook names.
- When changing visibility or execution identity, run the public-flag conversion before removing its source field. Keep public links, dashboard reachability, owner permissions, alert users, and the later removal of legacy permission fields in the same order.
- When changing workbook shares, preserve the distinction between read visibility and workbook edit access. Alert ownership and upgrade-item recipients depend on that distinction.
- When changing query source rules, copy nested sources and repoint dashboard filter links without copying variable secrets. Keep cycle and missing-value review items usable.
- When changing chart configuration normalization, keep the stored shape, chart readers, number-reading IDs, dashboard cell references, and the migration order aligned. A new normalization rule must remain stable when a current config is read again.
- When changing chart query derivation, update both the chart configuration consumers and the cleanup rule for obsolete derived query records. Do not delete a query that another query, chart, or alert still uses.
- When changing dashboard grid units or compact layout defaults, preserve the patch-log guard and update every stored breakpoint layout, not only the widest view.
- When changing export or data-store defaults, preserve the difference between an unset value and an intentional zero or saved customer limit.
- When changing dashboard preview generation, keep the current preview URL, private file ownership, attachment state, and cleanup of stale files aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Recent unmigrated v2 dashboard activity exists | Migration stops before the site can be upgraded | Migrate the v2 dashboards or set the explicit legacy-upgrade override after accepting data loss. |
| Workbook names remain numeric while link fields are text | Workbook listing or sharing can fail on PostgreSQL | Run the naming patch before model synchronization. |
| The demo file cannot be downloaded | Demo setup fails and the UI receives an error state | Check the remote source. Tests use generated fixture data instead. |
| A source is offline during column backfill | Column search remains incomplete for that source | Review the job output and run source sync or backfill after access returns. |
| Public content runs with an invalid owner or permission user | Readers see empty data or Not Permitted | Review the generated upgrade items and keep owner access valid before publishing. |
| Site-wide permission behavior changes without review | Users can lose access or see different rows and columns | Review the reported site-data findings and desk permissions. |
| A cross-workbook query copy lacks variable values | The copied query cannot run | Enter the variables listed in the workbook upgrade item. |
| A cross-workbook source cycle is copied | The copied query remains unusable | Remove the cycle named in the upgrade item. |
| A chart cache used by another query, chart, or alert is deleted | A live query or alert loses its source | Keep reference checks in cache retirement. |
| Number-card normalization runs after dashboard resizing | Stored card heights do not match current readings | Keep comparison normalization before resizing and splitting. |
| Dashboard row conversion runs twice | Saved cells move too far down and can overlap or leave gaps | Use the successful patch-log guard. |
| A stored chart keeps an old configuration shape or lacks a reading ID | Current readers and dashboard cells can interpret it differently | Run chart normalization after the number-card and dashboard patches. |
| A preview remains attached to a workbook or dashboard | Readers can download rows rendered for another user | Detach current private previews and delete stale or standard-dashboard previews. |
| A query variable is deleted but its secret remains | Sensitive data stays in the authentication store | Run orphaned-secret cleanup after variable records are current. |
Key files
| File | Why to read it |
|---|---|
| docker/docker-compose.yml | Defines the local MariaDB, Redis, and Frappe service boundary. |
| docker/init.sh | Shows how a new bench and insights.localhost site are created and started. |
| insights/hooks.py | Connects installation, migration, routes, and template discovery to the Frappe app lifecycle. |
| insights/…/demo.py | Defines demo source creation, data provisioning, table links, progress states, and workbook setup. |
| insights/…/setup_wizard.py | Defines the admin readiness check and user-facing setup failure boundary. |
| insights/…/spec.py | Describes the demo tables, value relationships, and seeded data shape. |
| insights/…/generator.py | Turns the demo specification into a checked DuckDB fixture. |
| insights/…/sample_workbook.json | Shows the portable workbook definition used by the demo. |
| insights/patches.txt | Defines the ordered pre-model-sync and post-model-sync patch contract. |
| insights/…/check_legacy_v2_data_before_upgrade.py | Protects active, unmigrated v2 dashboards from an unsafe upgrade. |
| insights/…/name_workbooks_as_strings.py | Preserves workbook links while changing workbook names to the current string model. |
| insights/…/backfill_table_columns.py | Restores saved column metadata for tables created before syncs recorded their shape. |
| insights/…/set_visibility_from_is_public.py | Moves legacy public chart and dashboard flags into current visibility before the old field is retired. |
| insights/…/run_public_charts_as_owner.py | Defines the transition to owner-based public chart execution. |
| insights/…/report_site_data_follows_desk.py | Reports access changes caused by the current site-table permission model. |
| insights/…/copy_cross_workbook_query_sources.py | Moves query dependencies into the workbook that uses them. |
| insights/…/retire_chart_query_cache.py | Removes obsolete derived queries without breaking live dependencies. |
| insights/…/resize_dashboard_cells.py | Converts saved dashboard cells to the current grid and content rules. |
| insights/…/split_number_cells.py | Gives each number-card reading its own dashboard cell. |
| insights/…/normalize_chart_configs.py | Brings stored chart configurations into the shape current readers use. |
| insights/…/share_workbooks_with_member_owners.py | Preserves edit access when workbook sharing becomes the access boundary. |
| insights/…/reshape_member_shares.py | Converts old member shares into workbook-level access or review items. |
| insights/…/report_upgrade_items.py | Collects changes that need an administrator or content owner to review. |
| insights/…/clear_standard_dashboard_previews.py | Removes standard-dashboard previews that can expose rendered rows. |
| insights/…/detach_dashboard_previews.py | Keeps current private previews available without document attachments. |
| docs/application-runtime.md | Explains the request and service lifecycle around deployment and migration. |
| docs/upgrade-and-legacy-migration.md | Explains the broader upgrade path and legacy migration concerns. |