Skip to content

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

11.3 KB
Raw Blame
## Add target_table_id FK to transform and table FKs on workspace input/output columns

databaseChangeLog:

  - changeSet:
      id: v61.2026-03-10T00:00:00
      author: christruter
      comment: Add target_table_id column to transform table
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:00:00
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - addColumn:
            tableName: transform
            columns:
              - column:
                  name: target_table_id
                  type: int
                  remarks: FK to metabase_table for the transform's target table
                  constraints:
                    nullable: true
      rollback:
        - dropColumn:
            tableName: transform
            columnName: target_table_id

  - changeSet:
      id: v61.2026-03-10T00:00:10
      author: christruter
      comment: Add index on transform.target_table_id
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:00:10
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - createIndex:
            tableName: transform
            indexName: idx_transform_target_table_id
            columns:
              - column:
                  name: target_table_id

  - changeSet:
      id: v61.2026-03-10T00:00:20
      author: christruter
      comment: Add FK from transform.target_table_id to metabase_table with SET NULL
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:00:20
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - addForeignKeyConstraint:
            baseTableName: transform
            baseColumnNames: target_table_id
            constraintName: fk_transform_target_table_id
            referencedTableName: metabase_table
            referencedColumnNames: id
            onDelete: SET NULL
      rollback:
        - dropForeignKeyConstraint:
            baseTableName: transform
            constraintName: fk_transform_target_table_id

  - changeSet:
      id: v61.2026-03-10T00:00:30
      author: christruter
      comment: Backfill transform.target_table_id from target JSON column
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:00:30
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - customChange:
            class: metabase.app_db.custom_migrations.BackfillTransformTargetTableId
      rollback:

  - changeSet:
      id: v61.2026-03-10T00:00:40
      author: christruter
      comment: Add index on workspace_output.global_table_id
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:00:40
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - createIndex:
            tableName: workspace_output
            indexName: idx_workspace_output_global_table_id
            columns:
              - column:
                  name: global_table_id

  - changeSet:
      id: v61.2026-03-10T00:00:50
      author: christruter
      comment: Add FK from workspace_output.global_table_id to metabase_table with SET NULL
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:00:50
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - addForeignKeyConstraint:
            baseTableName: workspace_output
            baseColumnNames: global_table_id
            constraintName: fk_workspace_output_global_table_id
            referencedTableName: metabase_table
            referencedColumnNames: id
            onDelete: SET NULL
      rollback:
        - dropForeignKeyConstraint:
            baseTableName: workspace_output
            constraintName: fk_workspace_output_global_table_id

  - changeSet:
      id: v61.2026-03-10T00:01:00
      author: christruter
      comment: Add index on workspace_output.isolated_table_id
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:01:00
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - createIndex:
            tableName: workspace_output
            indexName: idx_workspace_output_isolated_table_id
            columns:
              - column:
                  name: isolated_table_id

  - changeSet:
      id: v61.2026-03-10T00:01:10
      author: christruter
      comment: Add FK from workspace_output.isolated_table_id to metabase_table with SET NULL
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:01:10
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - addForeignKeyConstraint:
            baseTableName: workspace_output
            baseColumnNames: isolated_table_id
            constraintName: fk_workspace_output_isolated_table_id
            referencedTableName: metabase_table
            referencedColumnNames: id
            onDelete: SET NULL
      rollback:
        - dropForeignKeyConstraint:
            baseTableName: workspace_output
            constraintName: fk_workspace_output_isolated_table_id

  - changeSet:
      id: v61.2026-03-10T00:01:20
      author: christruter
      comment: Add index on workspace_input_external.table_id
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:01:20
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - createIndex:
            tableName: workspace_input_external
            indexName: idx_workspace_input_external_table_id
            columns:
              - column:
                  name: table_id

  - changeSet:
      id: v61.2026-03-10T00:01:30
      author: christruter
      comment: Add FK from workspace_input_external.table_id to metabase_table with SET NULL
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:01:30
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - addForeignKeyConstraint:
            baseTableName: workspace_input_external
            baseColumnNames: table_id
            constraintName: fk_workspace_input_external_table_id
            referencedTableName: metabase_table
            referencedColumnNames: id
            onDelete: SET NULL
      rollback:
        - dropForeignKeyConstraint:
            baseTableName: workspace_input_external
            constraintName: fk_workspace_input_external_table_id

  - changeSet:
      id: v61.2026-03-10T00:01:40
      author: christruter
      comment: Add index on workspace_output_external.global_table_id
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:01:40
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - createIndex:
            tableName: workspace_output_external
            indexName: idx_workspace_output_external_global_table_id
            columns:
              - column:
                  name: global_table_id

  - changeSet:
      id: v61.2026-03-10T00:01:50
      author: christruter
      comment: Add FK from workspace_output_external.global_table_id to metabase_table with SET NULL
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:01:50
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - addForeignKeyConstraint:
            baseTableName: workspace_output_external
            baseColumnNames: global_table_id
            constraintName: fk_workspace_output_external_global_table_id
            referencedTableName: metabase_table
            referencedColumnNames: id
            onDelete: SET NULL
      rollback:
        - dropForeignKeyConstraint:
            baseTableName: workspace_output_external
            constraintName: fk_workspace_output_external_global_table_id

  - changeSet:
      id: v61.2026-03-10T00:02:00
      author: christruter
      comment: Add index on workspace_output_external.isolated_table_id
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:02:00
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - createIndex:
            tableName: workspace_output_external
            indexName: idx_workspace_output_external_isolated_table_id
            columns:
              - column:
                  name: isolated_table_id

  - changeSet:
      id: v61.2026-03-10T00:02:10
      author: christruter
      comment: Add FK from workspace_output_external.isolated_table_id to metabase_table with SET NULL
      preConditions:
        - onFail: MARK_RAN
        - not:
            changeSetExecuted:
              id: v60.2026-03-10T00:02:10
              author: christruter
              changeLogFile: migrations/060_update_migrations.yaml
      changes:
        - addForeignKeyConstraint:
            baseTableName: workspace_output_external
            baseColumnNames: isolated_table_id
            constraintName: fk_workspace_output_external_isolated_table_id
            referencedTableName: metabase_table
            referencedColumnNames: id
            onDelete: SET NULL
      rollback:
        - dropForeignKeyConstraint:
            baseTableName: workspace_output_external
            constraintName: fk_workspace_output_external_isolated_table_id

  ## On rollforward, clean up any stale v60 changeset rows left from before the version bump.
  - changeSet:
      id: v61.2026-03-10T00:02:20
      author: christruter
      comment: >-
        Delete old v60 changeset rows for table_transform_target_fk migrations
        so the databasechangelog table only contains the v61 versions.
      changes:
        - sql:
            sql: >-
              DELETE FROM ${databasechangelog.name} WHERE id IN (
                'v60.2026-03-10T00:00:00',
                'v60.2026-03-10T00:00:10',
                'v60.2026-03-10T00:00:20',
                'v60.2026-03-10T00:00:30',
                'v60.2026-03-10T00:00:40',
                'v60.2026-03-10T00:00:50',
                'v60.2026-03-10T00:01:00',
                'v60.2026-03-10T00:01:10',
                'v60.2026-03-10T00:01:20',
                'v60.2026-03-10T00:01:30',
                'v60.2026-03-10T00:01:40',
                'v60.2026-03-10T00:01:50',
                'v60.2026-03-10T00:02:00',
                'v60.2026-03-10T00:02:10'
              );
      rollback: # nothing to undo - these rows should not exist in v61