Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

8.2 KB
Raw Blame
## Create data_app table for the data-app PoC.
##
## Data apps come from the repository connected via the remote-sync feature. The
## repo root has a `data_apps/` directory; each subdirectory is one app and
## contains a `data_app.yaml` (name/path/allowed_hosts) plus its built bundle. Each app dir
## is materialized as one row in this table on sync. The `bundle` / `bundle_hash`
## columns cache the last successfully synced bytes (nullable until first sync).

databaseChangeLog:
  - changeSet:
      id: v64.data-app1
      author: timofei
      comment: Create data_app table for Git-synced data-app bundles
      changes:
        - createTable:
            tableName: data_app
            remarks: Stores Git-synced data-app bundles, one row per data_apps/<dir> app.
            columns:
              - column:
                  name: id
                  type: int
                  autoIncrement: true
                  constraints:
                    primaryKey: true
                    nullable: false
              - column:
                  name: name
                  type: varchar(254)
                  remarks: Slug, used in the URL /apps/:name
                  constraints:
                    nullable: false
                    unique: true
              - column:
                  name: display_name
                  type: varchar(254)
                  remarks: Human-readable name from the manifest, shown in the admin UI
                  constraints:
                    nullable: false
              - column:
                  name: allowed_hosts
                  type: ${text.type}
                  remarks: JSON array of origins the sandboxed bundle may fetch/XHR. NULL when none configured.
                  constraints:
                    nullable: true
              - column:
                  name: bundle_path
                  type: varchar(1024)
                  remarks: Path within the repository to this app's built bundle file
                  constraints:
                    nullable: false
              - column:
                  name: bundle
                  type: ${blob.type}
                  remarks: Cached raw bytes of the last successfully synced bundle. NULL until first sync.
                  constraints:
                    nullable: true
              - column:
                  name: bundle_hash
                  type: varchar(64)
                  remarks: SHA-256 hex of the cached bytes, used as HTTP ETag. NULL until first sync.
                  constraints:
                    nullable: true
              - column:
                  name: last_synced_sha
                  type: varchar(40)
                  remarks: Git commit SHA the cached bundle was synced from
                  constraints:
                    nullable: true
              - column:
                  name: last_synced_at
                  type: ${timestamp_type}
                  remarks: Timestamp of the last successful sync for this app
                  constraints:
                    nullable: true
              - column:
                  name: sync_error
                  type: ${text.type}
                  remarks: Error from the most recent failed sync of this app, NULL when the last sync succeeded
                  constraints:
                    nullable: true
              - column:
                  name: enabled
                  type: ${boolean.type}
                  defaultValueBoolean: true
                  remarks: Admin toggle. When false the app is not served and is hidden from the data-app routes.
                  constraints:
                    nullable: false
              - column:
                  name: created_at
                  type: ${timestamp_type}
                  remarks: Timestamp when the data app was first synced
                  constraints:
                    nullable: false
              - column:
                  name: updated_at
                  type: ${timestamp_type}
                  remarks: Timestamp when the data app was last updated
                  constraints:
                    nullable: false

  - changeSet:
      id: v64.data-app2
      author: timofei
      comment: Use longblob for data_app.bundle on MySQL/MariaDB so it can hold multi-MB bundles
      changes:
        - modifyDataType:
            tableName: data_app
            columnName: bundle
            newDataType: longblob
      rollback:
        - modifyDataType:
            tableName: data_app
            columnName: bundle
            newDataType: ${blob.type}
      preConditions:
        - onFail: MARK_RAN
        - dbms:
            type: mysql,mariadb

  # --- Embedding analytics: attribute query executions / views to a concrete
  # embedding client (e.g. the data-app name) carried by the
  # X-Metabase-Client-Identifier header, alongside the other embedding attributes. ---

  - changeSet:
      id: v64.data-app3
      author: timofei
      comment: Add embedding_client_identifier column to query_execution for embedding analytics
      changes:
        - addColumn:
            tableName: query_execution
            columns:
              - column:
                  name: embedding_client_identifier
                  remarks: Identifier of the concrete embedding client (e.g. the data-app name) from the X-Metabase-Client-Identifier header
                  type: varchar(254)
                  constraints:
                    nullable: true

  - changeSet:
      id: v64.data-app4
      author: timofei
      comment: Add embedding_client_identifier column to view_log for embedding analytics
      changes:
        - addColumn:
            tableName: view_log
            columns:
              - column:
                  name: embedding_client_identifier
                  remarks: Identifier of the concrete embedding client (e.g. the data-app name) from the X-Metabase-Client-Identifier header
                  type: varchar(254)
                  constraints:
                    nullable: true

  - changeSet:
      id: v64.data-app5
      author: timofei
      comment: Updated view v_query_log v6 - add embedding_client_identifier (EMB-2088)
      changes:
        - sqlFile:
            dbms: postgresql
            path: ../instance_analytics_views/query_log/v6/postgres-query_log.sql
            relativeToChangelogFile: true
        - sqlFile:
            dbms: mysql,mariadb
            path: ../instance_analytics_views/query_log/v6/mysql-query_log.sql
            relativeToChangelogFile: true
        - sqlFile:
            dbms: h2
            path: ../instance_analytics_views/query_log/v6/h2-query_log.sql
            relativeToChangelogFile: true
      rollback:
        - sqlFile:
            dbms: postgresql
            path: ../instance_analytics_views/query_log/v5/postgres-query_log.sql
            relativeToChangelogFile: true
        - sqlFile:
            dbms: mysql,mariadb
            path: ../instance_analytics_views/query_log/v5/mysql-query_log.sql
            relativeToChangelogFile: true
        - sqlFile:
            dbms: h2
            path: ../instance_analytics_views/query_log/v5/h2-query_log.sql
            relativeToChangelogFile: true

  - changeSet:
      id: v64.data-app6
      author: timofei
      comment: Updated view v_view_log v5 - add embedding_client_identifier (EMB-2088)
      changes:
        - sqlFile:
            dbms: postgresql
            path: ../instance_analytics_views/view_log/v5/postgres-view_log.sql
            relativeToChangelogFile: true
        - sqlFile:
            dbms: mysql,mariadb
            path: ../instance_analytics_views/view_log/v5/mysql-view_log.sql
            relativeToChangelogFile: true
        - sqlFile:
            dbms: h2
            path: ../instance_analytics_views/view_log/v5/h2-view_log.sql
            relativeToChangelogFile: true
      rollback:
        - sqlFile:
            dbms: postgresql
            path: ../instance_analytics_views/view_log/v4/postgres-view_log.sql
            relativeToChangelogFile: true
        - sqlFile:
            dbms: mysql,mariadb
            path: ../instance_analytics_views/view_log/v4/mysql-view_log.sql
            relativeToChangelogFile: true
        - sqlFile:
            dbms: h2
            path: ../instance_analytics_views/view_log/v4/h2-view_log.sql
            relativeToChangelogFile: true