databaseChangeLog:
  - logicalFilePath: db-changelog-000495-add-data-fabric-dependency-table.yaml
  - changeSet:
      author: appian
      id: 'tag-pre-000495'
      tagDatabase:
        tag: 'pre-000495'

  - changeSet:
      author: appian
      id: '000495.1.0'
      comment: Add data_fabric_dependency table
      changes:
        - createTable:
            tableName: data_fabric_dependency
            columns:
              - column:
                  name: id
                  type: ${longType}
                  autoIncrement: ${autoIncrement}
                  constraints:
                    nullable: false
                    primaryKey: true
              - column:
                  name: record_type_uuid
                  type: ${uuidType}
                  constraints:
                    nullable: false
              - column:
                  name: dependent_type
                  type: ${byteType}
                  constraints:
                    nullable: false
              - column:
                  name: dependent_uuid
                  type: ${uuidtype}
                  constraints:
                    nullable: false
  - changeSet:
      author: appian
      id: '000495.1.1'
      comment: Create sequence to provide primary key value for data fabric dependency
      changes:
        - preConditions:
            onFail: MARK_RAN
            changeLogPropertyDefined:
              property: createSequence
              value: true
        - createSequence:
            sequenceName: data_fabric_dependency_sq
  - changeSet:
      id: '000495.1.2'
      author: appian
      comment: Add indices to data_fabric_dependency
      changes:
        - createIndex:
            tableName: data_fabric_dependency
            columns:
              - column:
                  name: record_type_uuid
            indexName: df_dep_record_uuid_idx
        - createIndex:
            tableName: data_fabric_dependency
            columns:
              - column:
                  name: dependent_uuid
            indexName: df_dep_dependent_uuid_idx

  - changeSet:
      id: '000495.2.0'
      author: appian
      comment: Create a table for linking data_fabric_dependency to mining_process with composite primary key
      changes:
        - createTable:
            tableName: mining_process_dep
            columns:
              - column:
                  name: mining_process_id
                  type: ${longtype}
                  constraints:
                    nullable: false
                    primaryKey: true
              - column:
                  name: dependency_id
                  type: ${longtype}
                  constraints:
                    nullable: false
                    primaryKey: true
  - changeSet:
      id: '000495.2.1'
      author: appian
      comment: Add FK from mining_process_dep.mining_process_id to mining_process.id
      addForeignKeyConstraint:
        constraintName: mining_process_dep_id_fk
        baseTableName: mining_process_dep
        baseColumnNames: mining_process_id
        referencedTableName: mining_process
        referencedColumnNames: id
        onDelete: CASCADE
  - changeSet:
      id: '000495.2.2'
      author: appian
      comment: Add FK from mining_process_dep.dependency_id to data_fabric_dependency.id
      addForeignKeyConstraint:
        constraintName: dependency_id_fk
        baseTableName: mining_process_dep
        baseColumnNames: dependency_id
        referencedTableName: data_fabric_dependency
        referencedColumnNames: id
